问题
I have a simple mongoDB query:
var qry = QueryBuilder.start
qry.and("website").exists(true)
qry.and("website").notEquals(null)
qry.and("_id").in(loc_ids)
website is a field in my collection, and loc_ids are a list of OIDs to each record...
The cursor does not result in any records returned from the query? Seems like the problem is the "website" : { "$exists" : true , "$ne" : ""}...
So my question is this a valid query creation:
var qry = QueryBuilder.start
qry.and("website").exists(true)
qry.and("website").notEquals(null)
qry.and("_id").in(loc_ids)
回答1:
Those commands return the current QueryBuilder object with your command appended. But you're not getting the return value, so the commands aren't appended. Chain them together like this and it should return the correct query:
qry = qry.and("website").exists(true).and("website").notEquals(null).and("_id").in(loc_ids)
As a side note, the Spring Data MongoDB driver is a little easier to use and makes more sense if you're familiar with how the console works.
来源:https://stackoverflow.com/questions/24025022/mongodb-querybuilder-query-creation-using-same-field