嗨,我正在使用 ReactiveMongo 和 Play,我希望能够在集合中运行 MongoDB 命令。
我的收藏是这样声明的:
def thingsJSONCollection : Future[JSONCollection] =
database.map( connectedDb =>
connectedDb.collection[JSONCollection]("thingsCollection")
)
我想执行的命令是这样声明的:
val commandDocument = Json.obj(
"geoNear" -> "thingsCollection",
"near" -> Json.obj(
"type" -> "Point",
"coordinates" -> Seq(lon, lat)),
"spherical" -> true,
"minDistance" -> 0,
"maxDistance" -> 5000
)
最后,这是无法编译的代码:
thingsJSONCollection.map{
collection => collection.runCommand( commandDocument )
}
当我尝试执行命令时,我收到一条很长的错误消息,基本上说不runCommand
接受JsObject
作为参数:
Error:(618, 57) overloaded method value runCommand with alternatives:
[C <: reactivemongo.api.commands.CollectionCommand](command: C)(implicit writer: collection.pack.Writer[reactivemongo.api.commands.ResolvedCollectionCommand[C]])reactivemongo.api.commands.CursorFetcher[collection.pack.type,reactivemongo.api.Cursor] <and>
[R, C <: reactivemongo.api.commands.CollectionCommand with reactivemongo.api.commands.CommandWithResult[R]](command: C with reactivemongo.api.commands.CommandWithResult[R])(implicit writer: collection.pack.Writer[reactivemongo.api.commands.ResolvedCollectionCommand[C]], implicit reader: collection.pack.Reader[R], implicit ec: scala.concurrent.ExecutionContext)scala.concurrent.Future[R]
cannot be applied to (play.api.libs.json.JsObject)
thingsJSONCollection.map(collection => collection.runCommand(commandDocument))
^
有人可以帮我找到在 Play 中使用 ReactiveMongo 在 MongoDB 集合中执行原始命令的方法吗?