db.inventory.insertMany([
{ item: "journal", qty: 25, tags: ["blank", "red"], dim_cm: [ 14, 21 ] },
{ item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ] },
{ item: "paper", qty: 100, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ] },
{ item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ] },
{ item: "postcard", qty: 45, tags: ["blue"], dim_cm: [ 10, 15.25 ] }
]);
return document that min(dim_cm)>15
it seems db.inventory.find( { dim_cm: { $all: {$gt:15} } } )
is wrong
2
Answers
Instead, you should work with
$not
and$lte
operators to find the document withdim_cm
contains all elements greater than 15.Demo @ Mongo Playground
Reference: Single Query Condition
An intuitive syntax would be chaining up
$min
and$gt
in an$expr
Mongo Playground