我在 MongoDB 中有一些文档,如下所示:
{
"no" : "ABC123",
"description": "The brown fox jumped over the lazy dog"
}
我希望能够搜索集合中的所有此类文档并返回所有包含描述中单词“fox”的文档。ReactiveMongo 有可能吗?谢谢
我在 MongoDB 中有一些文档,如下所示:
{
"no" : "ABC123",
"description": "The brown fox jumped over the lazy dog"
}
我希望能够搜索集合中的所有此类文档并返回所有包含描述中单词“fox”的文档。ReactiveMongo 有可能吗?谢谢
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))
}
这可以通过$text操作符来完成。