I have a "group" collection which groups documents from another "item" collection. The group collection is simply an array of ObjectId's from the item collection, however I want to make the objects in the group array more complex and still be able to use the $in and $nin operators.
How can I use $in when changing the value used with the $in operator to an object instead of only an ObjectId?
// current group document
{
_id: ObjectId(...),
items: [
ObjectId(...),
ObjectId(...)
]
}
// current item find query
db.item.find({ _id : { $in: group.items } }
I would like to change the group document to look like the following
{
_id: ObjectId(...),
items: [
{ _id : ObjectId(...), name: '...' },
{ _id : ObjectId(...), name: '...' }
]
}