Mongodb ReactiveMongo:find()在通过不同于_id的字段进行搜索时不返回任何内容

Mongodb ReactiveMongo:find()在通过不同于_id的字段进行搜索时不返回任何内容,mongodb,scala,reactivemongo,Mongodb,Scala,Reactivemongo,以下是应返回相同文档的四条语句,即id52dfc13ec20900c2093155cf和电子邮件me@gmail.com: val collection = ReactiveMongoPlugin.db.collection[JSONCollection]("users") collection.indexesManager.ensure( Index(List("email" -> IndexType.Ascending), unique = true) ) // Return

以下是应返回相同文档的四条语句,即id
52dfc13ec20900c2093155cf
和电子邮件
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
的第三个调用也工作,并返回与前面调用相同的文档。问题是最后一个电话。。。我希望它返回一个包含一个文档的列表,但它没有。它只返回一个空列表。我遗漏了什么吗?

您要求跳过一条记录作为查询的一部分

查询点(skipN=1))


我想你不是有意这么做的吧?

是的。。。原始代码是>>>collection.find(选择器).options(QueryOpts(skipN=page*perPage)).cursor[JsValue].collect[Vector](1)