i'm trying to do a $ne query in mongodb while using a regex, but it doesn't seem to work. the $ne (not equal) operator works fine when i don't use a regex though.
BasicDBObject q = new BasicDBObject()
q.put(field, ["\$ne": value])
the above works fine, the result set doesn't contain any documents that has that value for that field.
but i need it to be case insensitive. so i did this
q.put(field, ["\$ne": Pattern.compile(value, Pattern.CASE_INSENSITIVE)])
but this doesn't work..
so i thought, let me go to the command line and see if i can do it manually. so i did this:
db.Order.find({"bill.recipient.name": {$ne: /diep/i}},{"bill.recipient.name":1})
and it still doesn't work!
any ideas?
Try using $not instead of $ne.
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-Metaoperator%3A%24not
You can construct your query this way also
BasicDBObject query = new BasicDBObject();
query.append(fieldname,new BasicDBObject("$ne", value));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With