0.12.0-SNAPSHOT BSON BatchCommand.UpdateCommand + runCommand - Unable to find a writer?

18 views
Skip to first unread message

Stephen Couchman

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

I'm attempting to use the multi-update command from 2.6, but I'm getting the following error at runCommand:

could not find implicit value for parameter writer: c.pack.Writer[reactivemongo.api.commands.ResolvedCollectionCommand[c.BatchCommands.UpdateCommand.Update]]


I'm currently importing off of the collection object as:


import c.BatchCommands.UpdateCommand._


/* ... generate the updates list ... */


c
.runCommand(Update(ordered = false)(updates.head, updates.tail: _*))


Am I missing a required import?

Thanks,

~ Stephen

Cédric Chantepie

unread,
Jun 22, 2016, 10:32:05 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
Hi,

Why are you trying to use the generic command implementating, instead of the collection function .update ?

Stephen Couchman

unread,
Jun 22, 2016, 10:44:38 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
I need to perform multiple upserts (hundreds) and wanted to avoid the turnaround time and overhead of sending them all as individual update commands.

Cédric Chantepie

unread,
Jun 22, 2016, 10:53:41 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
What you are trying to do is re-implementing the .update operation, with no batching.

I can understand that you though BatchCommands means something like that, but that's wrong assumption: BatchCommands is a internal type used by the generic implementation of collection, taking care of the serialization pack abstraction. As a developer using ReactiveMongo, you should not deal with it.

The operations exposed on the collection API must definitely be looked at first, and in such case I would suggest you have a look a the bulkInsert one.

Stephen Couchman

unread,
Jun 22, 2016, 10:56:21 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
SOLVED

To clarify, I'm attempting to make use of this:

Which seems to be implemented in reactivemongo in: reactivemongo.api.collections.bson.BSONBatchCommands, though I'm using the import off the collection object ("c" in the example I gave).

In the process of looking up the path though it appears I discovered the answer to my own question.  The Reader/Writer for the Batch Update command are in the object BSONBatchCommands, and not in BSONUpdateCommand so my earlier imports weren't getting it.

Thanks

Cédric Chantepie

unread,
Jun 22, 2016, 11:04:11 AM6/22/16
to ReactiveMongo - http://reactivemongo.org
Please read the previous message. Anyway, BatchCommands is not intended for what you're trying to do, and moreover must be considered as internal class.

Cédric Chantepie

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

Stephen Couchman

unread,
Jun 22, 2016, 5:50:02 PM6/22/16
to ReactiveMongo - http://reactivemongo.org
Thank you, but I'm not sure you understood my intent completely.

I have 200 individual upsert requests to make, not a "multi" update, each one has to have its own query.  Unfortunately I cannot usefully predict if the items already exist and must be modified so bulkInsert is unlikely to help.  If I was to use .update I would need to call it 200 times and spend the cost of going across the network 200 times.

As the BSONBulkCommands.UpdateCommand.Update does take a list of UpdateElements, each with their own query and update documents and independent "upsert" option, it does seem to be the command identified here: https://docs.mongodb.com/manual/reference/command/update/#dbcmd.update (and used as I'm using it, here: https://docs.mongodb.com/manual/reference/command/update/#bulk-update ).

If you are certain I'm mistaken, please elaborate, obviously I would prefer that the code I'm writing be correct in the end.

Thanks

Cédric Chantepie

unread,
Jun 23, 2016, 3:13:57 AM6/23/16
to ReactiveMongo - http://reactivemongo.org
The .update operation is already using UpdateCommand as internal.

So if the update operation doesn't match your use case (you should first test the update command in MongoShell to understand, specially with multi and upsert).

On the other side if the MongoDB update command is what you need, you should not directly use the BatchCommands (which is for internal use), but that previously mentioned .update operation.

Reply all
Reply to author
Forward
0 new messages