像mongoDB中的查询 [英] like query in mongoDB
本文介绍了像mongoDB中的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在mongodb上工作.我想在其中使用类似查询.我的收藏结构如下.
I am working on mongodb . In which i Want to use like query. my collection structure is as follows.
{ "name" : "xy" , "age" : 34 , "location" : "sss"}
{ "name" : "xyx" , "age" : 45 , "location" : "sshs"}
{ "name" : "x" , "age" : 33 , "location" : "shhss"}
{ "name" : "pq" , "age" : 23 , "location" : "hhh"}
{ "name" : "pqr" , "age" : 12 , "location" : "sss"}
我想找到与"name":"x"匹配的记录.
i want to find records matching to "name" : "x".
因此查询将返回与xy,xyz,x匹配的所有三个记录.
so query will return all three records matching xy ,xyz,x.
在mongo中有可能吗?
Is it possible in mongo.
如果有人知道请答复.
谢谢
推荐答案
您可以使用正则表达式来做到这一点:
You can use regular expressions to do this:
db.customers.find( { name : /^x/i } );
您可能希望在名称字段上有一些索引.
You will probably want to have some indexes on the name field.
在 MongoDB Documetation 网站上了解更多信息.
Read more at the MongoDB Documetation site.
这篇关于像mongoDB中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文