Reading data back out uses find(), which returns every matching document, and findOne(), which returns just the first match.
Called with no arguments, find() returns every document in the collection:
db.users.find()Pass a query object to filter by field value — this returns every document where age is exactly 27:
db.users.find({ age: 27 })Use findOne() when you expect (or only care about) a single result — it returns one document object directly, not a list:
db.users.findOne({ email: "ananya@example.com" })Chain .pretty() in the shell to format results with indentation instead of a single line of JSON:
db.users.find().pretty()find() returns a cursor
find() actually returns a cursor, not an array — the shell automatically prints the first 20 results and lets you type it to see more. From application code (Node.js, later in this course), you typically convert the cursor to an array with .toArray().