I have a collection Events
in my Mongodb and it has an array filed called for_who
.
This field is for checking if a user id is in this array, so this user can see this Event
. I want to get the Events
that for_who
field contains user_id
.
This is my current query:
Events.find(
{ for_who: { "$in" : [user_id]} }
).lean().exec(function(err , obj) { ... });
my schema:
var eventSchema = new mongoose.Schema({
id : { type: Number , required: true , unique: true } ,
title : { type: String , required: true } ,
created_at : { type: String , required: true } ,
for_who : { type: Array }
});
var Events = mongoose.model('Events', eventSchema);