Querying

MongoDB features a rich language for performing dynamic queries.

Query Selectors

MongoDB supports a number of query expressions for fetching data. Queries are expressed in a JSON-style notation and transmitted to the database server as BSON. Queries on document keys include the ability to match against both embedded objects and arrays within a document.

The database's query optimizer analyzes each query and generates an appropriate plan, using indexes when available.

Cursors

Database queries, performed with the find() method, return a cursor. Cursors are then used to iteratively retrieve all the documents returned by the query. For example, in the mongo shell:

> var cur = db.example.find();
> cur.forEach( function(x) { print(tojson(x))});
{"n" : 1 , "_id" : "497ce96f395f2f052a494fd4"}
{"n" : 2 , "_id" : "497ce971395f2f052a494fd5"}
{"n" : 3 , "_id" : "497ce973395f2f052a494fd6"}
>

See Also


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.