content_image/690014.jpg content_image/690015.jpg
Distributed Queries (page 69) Describes how sharded clusters and replica sets affect the performance of read opera- tions. 

## Read Operations Overview 

Read operations, or queries , retrieve data stored in the database. In MongoDB, queries select documents from a single collection . 

Queries specify criteria, or conditions, that identify the documents that MongoDB returns to the clients. A query may include a projection that specifies the fields from the matching documents to return. The projection limits the amount of data that MongoDB returns to the client over the network. 

## Query Interface 

For query operations, MongoDB provides a db.collection.find() method. The method accepts both the query criteria and projections and returns a cursor (page 64) to the matching documents. You can optionally modify the query to impose limits, skips, and sort orders. 

The following diagram highlights the components of a MongoDB query operation: 

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

The next diagram shows the same query in SQL: 

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

## Example 

db.users.find( { age: { $gt: 18 } }, { name: 1, address: 1 } ).limit(5) 

This query selects the documents in the users collection that match the condition age is greater than 18 . To specify the greater than condition, query criteria uses the greater than (i.e. $gt ) query selection operator . The query returns at most 5 matching documents (or more precisely, a cursor to those documents). The matching documents will return with only the _id , name and address fields. See Projections (page 62) for details. 

## See 

SQL to MongoDB Mapping Chart (page 131) for additional examples of MongoDB queries and the corresponding SQL statements. 

