Compare Array with Collection-Array containing Objects

61 Views Asked by At

This is my collection schema:

    var objectSchema = new Schema({
    members: [{
        user_id: ObjectId,
        settings: {
            type: Boolean
        }
    }],
    title: String
});

And now I'm trying to search for objects with specific members (identified by their "user_id", for example ["asdf123lkd", "asdf1223"]). Is there any way to search for these objects?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

You can try this:

objectModel.find({ 'members.user_id' : {'$in' : ['asdf123lkd', 'asdf1223']} }, function(err, data) {
    console.log(err,data);
})