-
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
-
I guess you can't simply negate the $regex operator. Have you thought about simply defining a negating regex in the first place?