MongoDB Query Documents

MongoDB Query Documents – db.inventory.find(criteria)  is used to query all MongoDB Documents, or filter them based on a criteria, from a MongoDB Collection.

Examples

 

Example – Query All Documents in a Collection

To query all documents in a collection, use find() method with empty document as argument.

Following is the syntax of find command to query all documents

<collection>  is the name of the MongoDB Collection.

Following command queries all documents in people  collection present intutorialkart database

 

Example – Query Documents of a Collection based on a Criteria

Following example demonstrates to query those documents of a Collection that respect a criteria.

Select the database in which the collection is, using USE command.

Prepare a criteria to select documents

Use the criteria with find() method to select those documents that obey the criteria.

Run find(criteria) method

 

Conclusion :

In this MongoDB Tutorial MongoDB Query Documents  db.inventory.find(criteria)  is used to query all MongoDB Documents, or filter them based on a criteria, from a MongoDB Collection.