Mongoose.js: Find user by username LIKE value

前端 未结 13 1401
梦毁少年i
梦毁少年i 2020-11-27 10:48

I like to to go find a user in mongoDb by looking for a user called value. The problem with:

username: \'peter\'

is that i dont find it if

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 11:44

    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.

提交回复
热议问题