开发者

like query in 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"}

{ 开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜