Reputation: 1
Suppose I have a collection C with items with a property X. Suppose the values of X are themselves objects, list {a:1, b: 2, c: 3}
. Can I find (or findOne) on C asking for items whose X property has a value whose a property == 1
? I'd like to write C.find({X.a: 1})
. Or maybe
C.find({X: function(value) {
return value.a == 1;
}
});
Upvotes: 0
Views: 47
Reputation: 4138
Your pseudo code just needs quotes around the property for mongo to understand it. C.find({'X.a': 1})
would return any document where X.a equalled 1.
The key words if you want to learn more are 'subdocuments' and 'dot notation' as described here.
Upvotes: 1
Reputation: 1935
You can use dot notation to access the elements in nested documents but you will need to do $unwind if you need to access elements within a list and then check if X.a equals 1.
Upvotes: 0