Mongoose.js: Find user by username LIKE value

前端 未结 13 1403
梦毁少年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:45

    if I want to query all record at some condition,I can use this:

    if (userId == 'admin')
      userId = {'$regex': '.*.*'};
    User.where('status', 1).where('creator', userId);
    

提交回复
热议问题