Arun Tyagi Arun Tyagi - 4 months ago 7
Node.js Question

find elements on basis of array of input Mongoose

Model is

UserSchema = new Schema({
email: String,
erp_user_id:String,
isActive: { type: Boolean, 'default': true },
createdAt: { type: Date, 'default': Date.now }
});
module.exports = mongoose.model('User', UserSchema);


Now I have a list of string, which listt of [ erp_user_id], i want to search all users with erp_user_id contains in this list.

something like

var inputArray = ['1234','324324','54345'];

User.find({inputArray.contains(erp_user_id)}).exec(function(err,users){
user;// <---- list of users expected result
})

Answer
var inputArray = ['1234','324324','54345'];

User.find({erp_user_id:{$in:inputArray}}).exec(function(err,users){
user;//  <---- list of users expected result
})