Search code examples
mongodbmongoosemongodb-querysails-mongo

Find exactly match array or having all value of array in MongoDb


I have collection entry like that

[
 {
    shape : [{id:1,status:true},{id:2,status:false}]
 },
 {
    shape : [{id:1,status:true}]
 }
]

I want to fetch data which exactly match array , means contain all ele. of array.

Ex. where shape.id = [1,2] / [ {id: [1,2] } ] (any one is prefer)

then it should return only

[
 {
    shape : [{id:1,status:true},{id:2,status:false}]
 }
]

So help me if is there any native mongodb query .

Thanks

--ND


Solution

  • Here is much simpler query;

    db.shapes.find({'shape.id':{$all:[1,2]},shape:{$size:2}});