Luc*_*ssi 1 scala reactivemongo
假设我想要执行以下操作(在mongo shell中):
var bulk = db.vectors.initializeOrderedBulkOp()
bulk.find({"_id" : ObjectId("53f265da13d3f885ed8bf75d")}).updateOne({"$pop": {"v": 1}})
bulk.find({"_id" : ObjectId("53f265da13d3f885ed8bf75d")}).updateOne({"$push": {"v": 5}})
bulk.execute()
Run Code Online (Sandbox Code Playgroud)
我找到了答案!ReactiveMongo具有RawCommand命令,允许我们运行任何MongoDB命令(如更新,在本例中为>> http://docs.mongodb.org/manual/reference/command/update/#dbcmd.update):
val commandDoc =
BSONDocument(
"update" -> COLLECTION,
"updates" -> BSONArray(
BSONDocument("q" -> <query>, "u" -> BSONDocument("$pop" -> BSONDocument("v" -> 1))),
BSONDocument("q" -> <query>, "u" -> BSONDocument("$push" -> BSONDocument("v" -> 5)))
),
"ordered" -> true
)
// we get a Future[BSONDocument]
val futureResult = db.command(RawCommand(commandDoc))
futureResult.map { result => // result is a BSONDocument
//...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1306 次 |
| 最近记录: |