- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is return type of db.collection.find() in MongoDB?
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" }
Advertisements