Mongoose.js: Find user by username LIKE value Mongoose.js: Find user by username LIKE value mongoose mongoose

Mongoose.js: Find user by username LIKE value


For those that were looking for a solution here it is:

var name = 'Peter';model.findOne({name: new RegExp('^'+name+'$', "i")}, function(err, doc) {  //Do your action here..});


I had problems with this recently, i use this code and work fine for me.

var data = 'Peter';db.User.find({'name' : new RegExp(data, 'i')}, function(err, docs){    cb(docs);});

Use directly /Peter/i work, but i use '/'+data+'/i' and not work for me.


db.users.find( { 'username' : { '$regex' : req.body.keyWord, '$options' : 'i' } } )