I have a documents collection with document like this:
{
_id: ObjectId("5a9d218f9025gerg33759de016"),
date_created: 2018-03-05 12:53:03.323,
category: ObjectId("5a83064353113407626f2f67"),
category_params: [...],
related_items: Array
0: ObjectId("5a5ca8ab9025480234633a47"),
1: ObjectId("5a6ae99f902548125e9c441a"),
2: ObjectId("5a710ss048912543a0d8bda9"),
3: ObjectId("5a7ab77b12522243a0d8bee5"),
[...]
[...Other fields]
}
I try to do:
'$match': {
'related_items': {'$in': [related_item_id, ]}
}
But it does not seem to be helping.
I want to aggregate by the ObjectId
that is contained in related_items
array. e.g. with item #1 in that array (1: ObjectId("5a6ae99f902548125e9c441a"),
). How to do that? What $match aggregation should be it? Maybe not $match?
I'm doing pymongo aggregation. It does not matter however.