Performing simple queries

Command summary (discussed as follows):

  • db.<collection>.find({<filter>},{<projection>}).<aggregation>(): Returns only one or more documents based on the filter expression. The projection expression includes or excludes document fields. Aggregation is used to manipulate the final result set (for example, sort(), limit(), and so on).
  • db.<collection>.findOne({<filter>},{<projection>}): Returns only one document based on the filter expression. The projection expression includes or excludes document fields.

One of the most common operations on any database is querying the database for information, which will then form the basis of reports and information that might appear on a web page. In MongoDB the primary command ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.