-
Jun 16th, 2011, 09:57 AM
#1
MongoDB regex query ?
Hi mongoDB users,
from mongo shell I can execute the following query with no problem
db.item.find({ "label" : { "$not" : /12/i }})
how can I build the equivalent query using the mongo java driver oder spring-data mongo API ?
if I do:
DBObject tst = Criteria.where("label").not().regex("12").getCrite riaObject();
I get:
{ "label" : { "$not" : { "$regex" : "12"}}}
This query returns no result when executed from my java unit test.
If I execute the following from the mongo shell
db.item.find({ "label" : { "$not" : { "$regex" : "12"}}})
I get the following error:
error: {
"$err" : "can't use $not with $regex, use BSON regex type instead",
"code" : 13032
Can anyone help me here ?
Regards,
Dirk
-
Jun 18th, 2011, 01:32 AM
#2
I guess you can't simply negate the $regex operator. Have you thought about simply defining a negating regex in the first place?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules