I'm having trouble with query the DB, I want to get all element that the have for example: admin "54bd13864ec56c7c12310a79" in the admins array,
tried it with "$in" but it didn't worked, could it be related to the fact that its an ObjectId?
trainerId = '54bd13864ec56c7c12310a79'
GroupSchema.find({'admins': { $in: [ trainerId ] }}
This is my db:
{
"_id" : ObjectId("54b93e8e3801ae381e3433be"),
"groupName" : "Developers Groups",
"createdBy" : "Ido",
"creationDate" : "Jan 16 2015",
"users" : [
ObjectId("54b932c7ac3ec34a85e6246c")
],
"admins" : [
ObjectId("54b932c7ac3ec34a85e6246c"),
ObjectId("54bd13864ec56c7c12310a79")
],
"__v" : 0
}
The Schema model is:
module.exports = mongoose.model('Groups' ,
{
groupName: String,
createdBy: String,
creationDate: String,
admins: [{ type : mongoose.Schema.Types.ObjectId, ref: 'Users' }],
users: [{ type : mongoose.Schema.Types.ObjectId, ref: 'Users' }]
}
);