I use Casbah to connect to the Mongo database and query. Right now I am trying to query for fields where the value is non-zero.
Using Mongo's direct syntax, the query I want will be collection.find({"key" : {$ne : null }} )
In casbah, I tried collection.find("key" $ne null) , which does not compile, and collection.find("key" $ne MongoDBObject(null)) , which throws a null pointer exception at runtime, as well as collection.find("key" $ne org.bson.BSON.NULL) , which is not really requesting properly.
collection.find("key" -> null) will work to query those that are null.
In the examples above, my syntax could be discarded, but the main idea should be conveyed.
Any ideas anybody?
I cannot change the database so that null records simply do not exist. This is out of control. I can change to not casbah, but I really would not want to.
source share