开发者

how do I exlude term in mongodb query

I am开发者_如何学JAVA having urls in this format stored in mongodb

Source:
index.php?name=xxxxxxxxxxxxxabcxxxxxxxx&id=15&success=1
index.php?name=xxxxxxxdefxxxxxxxxxxxx&id=18&success=0

where xxxxxxxxxxxxxxx is some string

I want to write a query to find all sources where name should not contain "abc" as a substring So I wrote the query

db.coll.find({source:/(?!name=abc)/})

but this query is not working..please guide me what will be the correct query


db.coll.find({source: {$not: /[?&]name=.*abc.*(&|$)/}})

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-Metaoperator%3A%24not


regex w/ $nin (not in). Don't think that is supported as a single query yet...

try looking at

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24nin

http://jira.mongodb.org/browse/SERVER-322

https://github.com/mongodb/mongo/commit/6c7dc2b0f8831fac6621f125889d873241588b02

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜