Mongoose.js: Find user by username LIKE value(Mongoose.js:通过用户名 LIKE 值查找用户)
问题描述
我喜欢通过查找名为 value 的用户在 mongoDb 中查找用户.问题:
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 那样做
So i want to do like 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 值查找用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Mongoose.js:通过用户名 LIKE 值查找用户


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01