我想是很简单的。在mongo上执行时:
db.topic.find({"user_id":ObjectId("52e39be16700006700d646ad"), "post_id":null})它将列出post_id为null或不存在的所有主题。这个很好用。
但是,在使用Scala代码时,我尝试使用以下无法工作的代码:
val cursor = db("topic").find(
BSONDocument("user_id" -> user.id),
BSONDocument("post_id" -> null)).cursor[Topic]
cursor.collect[List]()基本上,我必须更改条件BSONDocument("post_id“-> null)。但是怎么做呢?
非常感谢!马塞尔
发布于 2014-01-31 00:05:54
在mongo查询中,您有一个定义查询子句的JSON文档,但在Scala代码中,您有2个JSON文档,因此第二个文档定义投影,就像在Mongo中那样。这是def find[S, P](selector: S, projection: P)... 文档。您需要在两个文档中创建一个包含两个字段的文档,如下所示:
val cursor = db("topic").find(
BSONDocument("user_id" -> user.id, "post_id" -> null)).cursor[Topic]
cursor.collect[List]()https://stackoverflow.com/questions/21469289
复制相似问题