For example, I have these documents in my collection.
{
_id: ObjectId("5234cc89687ea597eabee675"),
code: "xyz",
tags: [ "school", "book", "bag", "headphone", "appliance" ],
qty: [
{ size: "S", num: 10, color: "blue" },
{ size: "M", num: 45, color: "blue" },
{ size: "L", num: 100, color: "green" }
]
}
{
_id: ObjectId("5234ccb7687ea597eabee677"),
code: "efg",
tags: [ "school", "book" ],
qty: [
{ size: "S", num: 10, color: "blue" },
{ size: "S", num: 100, color: "blue" },
{ size: "S", num: 100, color: "green" }
]
}
I want to get the second document, every 'size' is 'S'.
I have tried $all and $elemMatch
(like this: https://docs.mongodb.com/manual/reference/operator/query/all/#use-all-to-match-values), but it still return me both of them.
Is there any other way to do this?
I know I can use $aggregate with $unwind, $project... to make it, but if I want to update it, what should I do. I just want to find(update) the document that all 'size' in its 'qty' are 'S', not some of them are 'S'.