Mongoose.js:按用户名 LIKE 值查找用户 [英] Mongoose.js: Find user by username LIKE value
本文介绍了Mongoose.js:按用户名 LIKE 值查找用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我喜欢在 mongoDb 中通过查找名为 value 的用户来查找用户.问题在于:
I like to to go find a user in mongoDb by looking for a user called value. The problem with:
username: 'peter'
如果用户名是Peter"或PeTER"..或类似的东西,我找不到它.
is that i dont find it if the username is "Peter", or "PeTER".. or something like that.
所以我想做 sql
SELECT * FROM users WHERE username LIKE 'peter'
希望你们能得到我想要的吗?
Hope you guys get what im askin for?
简短:mongoose.js/mongodb 中的字段 LIKE 值"
推荐答案
对于那些在这里寻找解决方案的人来说:
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..
});
这篇关于Mongoose.js:按用户名 LIKE 值查找用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文