MongoDB QueryBuilder查询使用相同的字段创建 [英] MongoDB QueryBuilder query creation using same field

查看:609
本文介绍了MongoDB QueryBuilder查询使用相同的字段创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的mongoDB查询:

$ p $ var cry = QueryBuilder.start
qry.and(website (true)
qry.and(website)。notEquals(null)
qry.and(_ id)。in(loc_ids)

$ b $ p
$ b

b $ b

游标不会导致查询返回任何记录?似乎问题是网站:{$存在:真正的$ ne:} ...

所以我的问题是这个有效的查询创建:

  var qry = QueryBuilder.start 
qry.and(website)。exists(true )
qry.and(website)。notEquals(null)
qry.and(_ id)。in(loc_ids)
解决方案

这些命令返回当前QueryBuilder对象的附加命令。但是你没有得到返回值,所以命令不会被追加。将它们链接在一起就像这样,它应该返回正确的查询:
$ b $ p $ q $ qry = qry.and(website)。exists(true)。在(loc_ids)



如果您熟悉控制台的工作方式,那么Spring Data MongoDB驱动程序更容易使用,并且更有意义。


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)

解决方案

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.

这篇关于MongoDB QueryBuilder查询使用相同的字段创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆