开发者

like query in mongoDB

开发者 https://www.devze.com 2023-02-17 22:58 出处:网络
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\"}

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"}

{ 开发者_Python百科"name" : "xyx" , "age" : 45 , "location" : "sshs"}

{ "name" : "x" , "age" : 33 , "location" : "shhss"}

{ "name" : "pq" , "age" : 23 , "location" : "hhh"}

{ "name" : "pqr" , "age" : 12 , "location" : "sss"}

i want to find records matching to "name" : "x".

so query will return all three records matching xy ,xyz,x.

Is it possible in mongo.

if any one knows plz reply.

Thanks


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.

Read more at the MongoDB Documetation site.


you can visite http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions

You may use regexes in database query expressions!

0

精彩评论

暂无评论...
验证码 换一张
取 消