Reputation: 135
How would you write this MongoDB query using Java driver :
db.customers.find({'arrayName' : {$exists:true}, $where:'this.arrayName.length>0'})
Cheers, Yann
Upvotes: 0
Views: 187
Reputation: 69663
To build a query with the Java driver, you substitute any Javascript objects with DBObject
's.
DBObject condition = new BasicDBObject();
condition.put("arrayName", new BasicDBObject("$exists", true));
condition.put("$where", "this.arrayName.length>0");
DBCursor result = yourDatabase.getCollection("customers").find(condition);
Upvotes: 1