Collection.find() for array inside object Collection.find() for array inside object mongoose mongoose

Collection.find() for array inside object


Something like this:

ChatGroups.find({whitelist: Meteor.user().username});

This assumes that username is the property you want to match against. You don't need to do anything special to search within an array in this case - mongo will do the correct thing (compare username to each element of each whitelist and return those documents that match).


To search in MongoDB by array items - use $in operator:

ChatGroups.find({   whitelist: {      $in: [Meteor.user()._id]   }});

Reference: Comparison Query Operators > $in