Database Reference
In-Depth Information
Queries and Aggregation
The update command has used simple queries to identify the document to
change. MongoDB, in general, has a fairly rich query language, although it
can often be cumbersome as it is expressed as JSON, just like any other
document. Queries are conducted using the find command, and they rely
heavily on the indexing of collections to achieve performance. If an index is
not available, then all of the documents in a collection will be scanned.
The queries used in the previous section are simple matching queries,
equivalent to using an = in the WHERE clause of a SQL query. If the field
being queried is an array, this equality query returns the document if any of
the elements of the array matches the query value.
To use inequalities to specify range queries, the $lt and $gt fields can be
used (along with $lte and $gte for inclusive inequalities). For example,
to find all entries with a timestamp after midnight on December 1 st , the
following query could be used:
> db.metrics.find({customer_id:1,ts:{$gte:new
Date(2013,11,01)}});
Tomatchanyofseveraloptions,the $in fieldcanbeusedinthequeryalong
with an array:
> db.metrics.find({customer_id:{$in:[1,2,3,]}});
Search WWH ::




Custom Search