Q: Mongoose query to check for specific value in array of searched element I have s schema like:
var EntitySchema = new Schema({
  name : {type: String, default: null},
  organizations : [{
    id: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Organization'
    }}]
});

I have an id of organization, How can I make a query for Entity.find({}) and find Entity that has this id in its organizations array?
I used this in mongo shell
db.entity.find({"organizations.id": { $in: [ObjectId("ididididididid")]}}).pretty()

and it worked, but it doesn't work in express method, do I do something wrong? Does $in works both ways? I have a feeling that its not what I should be using in this query.

A: As per mongo documentation, you can query as below
db.entity.find({ "organizations" : { $elemMatch: { "id" : ObjectId("ididididididid") } }}).pretty();

Ref: 
https://docs.mongodb.com/manual/tutorial/query-array-of-documents/
