4

我在 MongoDB 中有一些文档,如下所示:

{
  "no" : "ABC123",
  "description": "The brown fox jumped over the lazy dog"
}

我希望能够搜索集合中的所有此类文档并返回所有包含描述中单词“fox”的文档。ReactiveMongo 有可能吗?谢谢

4

2 回答 2

4

ReactiveMongo实际上,您要解决的问题与驾驶员无关。

例如,您可以使用$regex命令在 mongodb 中搜索字符串,如下所示:

def coll: JSONCollection = db collection "your_collection"

val nameToFind = "Andrey"
val query = obj("name" -> obj("$regex" ->  (".*" + nameToFind + ".*")))
coll.find(query).cursor[JsObject].collect[List]() map {
  case objects => Ok(obj("result" -> objects))
}
于 2014-04-20T18:41:11.273 回答
2

这可以通过$text操作符来完成。

于 2014-05-08T10:14:30.063 回答