MongoDB QueryBuilder query creation using same field

ε祈祈猫儿з 提交于 2019-12-13 04:23:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!