for exact match, we need to use the below
db.inventory.find( { tags: ["red", "blank"] } )
below finds array that contains both elements but not in specific order, i.e. not exact match.
db.inventory.find( { tags: { $all: ["red", "blank"] } } )
below queries any array that contains at least "red"
db.inventory.find( { tags: "red" } )
below queries an array which has value > 25
db.inventory.find( { dim_cm: { $gt: 25 } } )
below queries dim_cm array that satisfy condition in any form. for e.g. one can satisfy > 15 and another can satisfy < 20
or one can satisfy both.
db.inventory.find( { dim_cm: { $gt: 15, $lt: 20 } } )
below queries element at the given index position.
db.inventory.find( { "dim_cm.1": { $gt: 25 } } )
references:
https://docs.mongodb.com/manual/tutorial/query-arrays/
db.inventory.find( { tags: ["red", "blank"] } )
below finds array that contains both elements but not in specific order, i.e. not exact match.
db.inventory.find( { tags: { $all: ["red", "blank"] } } )
below queries any array that contains at least "red"
db.inventory.find( { tags: "red" } )
below queries an array which has value > 25
db.inventory.find( { dim_cm: { $gt: 25 } } )
below queries dim_cm array that satisfy condition in any form. for e.g. one can satisfy > 15 and another can satisfy < 20
or one can satisfy both.
db.inventory.find( { dim_cm: { $gt: 15, $lt: 20 } } )
below queries element at the given index position.
db.inventory.find( { "dim_cm.1": { $gt: 25 } } )
references:
https://docs.mongodb.com/manual/tutorial/query-arrays/
No comments:
Post a Comment