content_image/786048.jpg
## Query Behavior 

MongoDB queries exhibit the following behavior: 

• All queries in MongoDB address a single collection. 

• You can modify the query to impose limits , skips , and sort orders . 

• The order of documents returned by a query is not defined unless you specify a sort() . 

• Operations that modify existing documents (page 102) (i.e. updates ) use the same query syntax as queries to select documents to update. 

• In aggregation (page 439) pipeline, the $match pipeline stage provides access to MongoDB queries. 

MongoDB provides a db.collection.findOne() method as a special case of find() that returns a single document. 

## Query Statements 

Consider the following diagram of the query process that specifies a query criteria and a sort modifier: 

<img src='content_image/786048.jpg'>

In the diagram, the query selects documents from the users collection. Using a query selection operator to define the conditions for matching documents, the query selects documents that have age greater than (i.e. $gt ) 18 . Then the sort() modifier sorts the results by age in ascending order. 

For additional examples of queries, see Query Documents (page 96). 

## Projections 

Queries in MongoDB return all fields in all matching documents by default. To limit the amount of data that MongoDB sends to applications, include a projection in the queries. By projecting results with a subset of fields, applications reduce their network overhead and processing requirements. 

