0

I am refactoring an application to use the mongo-scala driver version 2.0 instead of reactivemongo. From working with reactivemongo and casbah I have come to expect to be able to update a document by providing a query to find the target document and a new document to update it with.

The method in Casbah looks like this (copied from here.)

def update[A, B](q: A, o: B, <...some other stuff...>): 
TypeImports.WriteResult

Performs an update operation.
q: search query for old object to update
o: object with which to update q

It seems I cannot do this using the mongo-scala driver but instead must provide each field to be updated and its new value. The problem is that the only reliable way to update everything that may have changed is to pass in a new document.

So I wonder whether I am just missing something obvious or there really is no way to do what I want with the mongo-scala driver? Has anyone found a reasonable work-around for this missing functionality?

KevinD
  • 31
  • 3
  • With updates, you need to use update operators. Did you try the replace methods? – RavenMan May 09 '17 at 22:56
  • I wasn't aware of any `replace` methods until you mentioned them. I found them in the scaladoc for `MongoCollection`. They look like what I need. Thank you! – KevinD May 09 '17 at 23:11

0 Answers0