Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String mongoDb忽略资本_String_Mongodb_Request - Fatal编程技术网

String mongoDb忽略资本

String mongoDb忽略资本,string,mongodb,request,String,Mongodb,Request,我想设置一个mongoDb请求 如果我只有一个测试用户名的用户 db.users.find( { username: "test" } ) 我会归还一些东西 我想返回配置文件测试 db.users.find( { username: "Test" } ) 或 但我不知道我是否应该忽略大写字母 同样的问题,如果我有一个用户名托比,我想找到 db.users.find( { username: "toby" } ) 谢谢您可以使用正则表达式忽略大写字母,如: db.us

我想设置一个mongoDb请求

如果我只有一个测试用户名的用户

db.users.find(
    { username: "test" }
)
我会归还一些东西 我想返回配置文件测试

db.users.find(
    { username: "Test" }
)

但我不知道我是否应该忽略大写字母

同样的问题,如果我有一个用户名托比,我想找到

db.users.find(
    { username: "toby" }
)

谢谢

您可以使用正则表达式忽略大写字母,如:

db.users.find({username: /test/i})
因此,
i
选项的状态不区分大小写。但是,这不是非常友好的索引


更好的选择是在客户端执行此操作。将您的案例标准化,使所有内容都是小写或大写。这样您就可以正常进行测试。

似乎是重复的,可以在那里找到丰富的答案:
db.users.find({username: /test/i})