The statement db.collection.find() returns the cursor of Result Set of a query by which you can iterate over the result set or print all documents.
Let us first create a collection with documents −
> db.findCursorDemo.insertOne({"ClientFirstName":"John","ClientLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd00a1c588d4a6447b2e05c") } > db.findCursorDemo.insertOne({"ClientFirstName":"Carol","ClientLastName":"Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd00a26588d4a6447b2e05d") } > db.findCursorDemo.insertOne({"ClientFirstName":"David","ClientLastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd00a33588d4a6447b2e05e") }
Following is the query to display all documents from a collection with the help of find() method −
> db.findCursorDemo.find();
This will produce the following output −
{ "_id" : ObjectId("5cd00a1c588d4a6447b2e05c"), "ClientFirstName" : "John", "ClientLastName" : "Smith" } { "_id" : ObjectId("5cd00a26588d4a6447b2e05d"), "ClientFirstName" : "Carol", "ClientLastName" : "Taylor" } { "_id" : ObjectId("5cd00a33588d4a6447b2e05e"), "ClientFirstName" : "David", "ClientLastName" : "Miller" }