How to use mongo `$in` with nested object?


#1

I would like to use $in with nested object, but don’t work

$match: {
            items: { itemId: { $in: ['001', '002', '003'] }}
}

Please help me


#2

have you tried { items: { $elemMatch: { itemId: { $in: ['001', '002', '003'] }}}}


#3

Thanks for your reply, but still don’t work.
I tried with string nested, It work fine

$match: {
     'items.itemId': { $in: ['001', '002', '003'] }
}

Why? I don’t understand


#4

Thats just how nested queries are defined in mongo right?