Is there any way to perform bulk updates on ReactiveMongo?

后端 未结 2 870
夕颜
夕颜 2021-01-23 18:14

Suppose I want to do the following (in mongo shell):

var bulk = db.vectors.initializeOrderedBulkOp()

bulk.find({\"_id\" : ObjectId(\"53f265da13d3f885ed8bf75d\")         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 18:31

    I found the answer! ReactiveMongo has RawCommand command that let us run any MongoDB command (like update, in this case >> http://docs.mongodb.org/manual/reference/command/update/#dbcmd.update):

      val commandDoc =
            BSONDocument(
              "update" -> COLLECTION,
              "updates" -> BSONArray(
                BSONDocument("q" -> , "u" -> BSONDocument("$pop" -> BSONDocument("v" -> 1))),
                BSONDocument("q" -> , "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
               //...
          }
    

提交回复
热议问题