0

以下是应该返回相同文档的四个语句,即具有 id52dfc13ec20900c2093155cf和 email的语句me@gmail.com

val collection = ReactiveMongoPlugin.db.collection[JSONCollection]("users")

collection.indexesManager.ensure(
  Index(List("email" -> IndexType.Ascending), unique = true)
) 

// Returns one document, i.e. the one identified by 52dfc13ec20900c2093155cf
collection.find(Json.obj("_id" -> Json.obj("$oid" -> "52dfc13ec20900c2093155cf"))).cursor[JsValue].headOption

// Returns a list containing one element, i.e. the one identified by 52dfc13ec20900c2093155cf
val query = collection.find(son.obj("_id" -> Json.obj("$oid" -> "52dfc13ec20900c2093155cf"))).options(QueryOpts(skipN = 1)).cursor[JsValue].collect[Vector](1)

// Returns the same document as above, but found by email instead of by id
collection.find(Json.obj("email" -> "me@gmail.com")).cursor[JsValue].headOption

// Returns an empty list (it should return the same document as above)
val query = collection.find(Json.obj("email" -> "me@gmail.com")).options(QueryOpts(skipN = 1)).cursor[JsValue].collect[Vector](1)

前两个调用find按预期工作,即它们返回由给定 id 标识的文档。第三次调用find也可以工作,并返回与前面调用相同的文档。问题是最后一次调用......我希望它返回一个包含一个文档的列表,但事实并非如此。它只返回一个空列表。我错过了什么吗?

4

1 回答 1

1

您要求在查询中跳过一条记录。

QueryOpts(skipN = 1))

我假设你不打算这样做?

于 2014-02-11T20:46:35.363 回答