I'm new on MongoDB.
I want to find document with matching of whole array.
let show you collection schema. here is combination collection data
{
_id: 741258,
product_id: 258,
attributes: [ { attr_id: 123, val: '26' },
{ attr_id: 456, val: 'Blue' },
{ attr_id: 789, val: 'Slim' } ],
},
{
_id: 745896,
product_id: 258,
attributes: [ { attr_id: 124, val: '28' },
{ attr_id: 484, val: 'Red' },
{ attr_id: 852, val: 'Small' } ],
},
{
_id: 985632,
product_id: 258,
attributes: [ { attr_id: 123, val: '26' },
{ attr_id: 456, val: 'Blue' } ],
},
{
_id: 456855,
product_id: 258,
attributes: [ { attr_id: 123, val: '26' } ],
}
Query :
db.combination.find( { product_id: "258" },
{ attributes: { $elemMatch: [ { attr_id: 123, val: '26' },
{ attr_id: 456, val: 'Blue' }
] } } )
Error :
(node:4460) UnhandledPromiseRejectionWarning: MongoError: $elemMatch needs an Object
Expected Result :
{
_id: 985632,
product_id: 258,
attributes: [ { attr_id: 123, val: '26' },
{ attr_id: 456, val: 'Blue' } ],
},
Please help to slow this issue. Thanks in advance