Aneesh Aneesh - 3 months ago 9
Node.js Question

FindAll documents that has an array of sub-documents

Following is an example model:

UserModel == {
name: String,
friends: [ObjectId],
}


friends corresponds to a list of id of objects of some other model for example AboutModel.

AboutModel == {
name: String,
}


Is it possible to find all
Users
who have a friend with
_id="1234"
in
friends
array?

Answer
user.find({friends: {$in: ['1234']}})