BulkUpdate Operation?

62 views
Skip to first unread message

Tulio Domingos

unread,
Jun 22, 2016, 11:15:03 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
Hi there, 

I'm looking to update multiple documents in a collection with some sort of upsert flag. Similar to MongoDB's updateMany operation I guess: https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/


The problem is that I need to insert docs either way (overwriting existing docs if found), the only way I found possible so far is to iterate over every single one of them programatically and upsert each of them individually..

Wondering if there is a better way of doing this? 

Thanks in advance  
 
 

Cédric Chantepie

unread,
Jun 22, 2016, 11:18:54 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
Hi,

If you have a look at the .update operation, you can see a multi flag.
When true, the update is applied on all the documents matching the given selector.

Tulio Domingos

unread,
Jun 22, 2016, 11:49:55 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
Thanks for the prompt reply! 

Should the selector then be a list of BSON Documents with ID fields? 

val selector = List(BSONDocument("_id" -> "xxx"), ...)

And the modifier, the collection of objects (with implicit reader and writers)? 

Maybe I'm missing something but it doesn't make much sense to me, basically I just want to insert a bunch of objects, and while doing so, update the ones that match on the _id field..  

Thanks

Cédric Chantepie

unread,
Jun 22, 2016, 1:19:04 PM6/22/16
to ReactiveMongo - http://reactivemongo.org
The update command provided by MongoDB expected BSON documents for both the selector/filter and the update operation.
I suggest you first try manually using the MongoShell, to understand the MongoDB behaviour, then you can do the same using ReactiveMongo.

Tulio Domingos

unread,
Jun 22, 2016, 5:11:58 PM6/22/16
to ReactiveMongo - http://reactivemongo.org
I'll take a look at it, thanks Cédric!
Reply all
Reply to author
Forward
0 new messages