MongoDB documentation uses words like query, expression, query predicate, clause but I'm unable to find their precise meaning.
For example syntax of $elemMatch
is defined as
{ <field>: { $elemMatch: { <query1>, <query2>, ... } } }
but I don't know what does query1
, query2
mean. The same article about $elemMatch
mentions word query predicate:
If you specify a single query predicate in the
$elemMatch
expression,$elemMatch
is not necessary.
But they don't specify what does it mean. Is there a place in the documentation (or in Mongo source code) where these words are precisely defined?
To be more concrete: I'm trying to understand how to form valid queries. For example why with this database
db.inventory.insertMany([
{ item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ {value: 49} ] }
]);
following query works
db.inventory.find( {dim_cm: { $elemMatch :{ $or: [{value: 49}] } }} )
but query without $elemMatch
doesn't:
db.inventory.find( {dim_cm: { $or: [{value: 49}] } })
Even though the documentation states If you specify a single query predicate in the $elemMatch
expression, $elemMatch
is not necessary.