Reputation: 14185
my documents "parents" got the folowing structure:
{childrenIdList: [23, 24, 34]}
{childrenIdList: [23, 88]}
{childrenIdList: [1, 5, 8]}
how to select parents by childId
in there childrenIdList?
Such query must return first two documents of 3 in my example if childId = 23
.
I tried to use elemMatch method, but seemingly it works only with objects, i.e. it would work only if my data would be {childrenIdList: [{Id: 1}, {Id: 5}, {Id: 8}]}
Upvotes: 0
Views: 31
Reputation: 42073
You can just use db.collection.find({childrenIdList: 23})
. See the Query Arrays section in the manual for more details.
Upvotes: 1