Hitting assert "update object must consist of $-prefixed modifiers" in mongo-cxx-driver/src/mongo/client/bulk_update_builder.cpp

38 views
Skip to first unread message

Sumanta Dutta

unread,
Mar 15, 2017, 7:35:32 PM3/15/17
to mongodb-user
Hi,

We use MongoDB C++ driver v1.1.0 and DB v3.2.11. 

I am trying to bulk update entire document using find(key).updateOne(replacementDoc). 
The replacementDoc doesn't have _id field as per documentation https://docs.mongodb.com/manual/reference/method/Bulk.find.updateOne/

I am getting the following error -

  Exception of type "mongo::UserException"
  Message: update object must consist of $-prefixed modifiers

Any idea why it's expecting $-prefixed modifiers? I didn't want to use $set as some of the fields may not be present in the replacementDoc. 
In which case, those fields should be absent in the updated document. So it's better to replace the entire document.

Thanks,
Sumanta

David Golden

unread,
Mar 16, 2017, 9:12:05 AM3/16/17
to mongodb-user
Hi.

If you're replacing the entire document, you need to use "replaceOne", not "updateOne".

Regards,
David

Sumanta Dutta

unread,
Mar 16, 2017, 11:34:20 AM3/16/17
to mongodb-user
David, let me give that a try. But why does the MongoDB documentation link has 'Replace a Document' section for updateOne? 
Thanks,
Sumanta

David Golden

unread,
Mar 17, 2017, 8:56:20 AM3/17/17
to mongodb-user
I don't know.  Maybe it's a doc rendering bug.  Can you give me a link to the exact page you're seeing that?

Thanks,
David

Sumanta Dutta

unread,
Mar 17, 2017, 9:29:34 AM3/17/17
to mongod...@googlegroups.com
David, the link is my original post. BTW, replaceOne worked as expected.

Thanks,
Sumanta

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/yMIV6qzQOeo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/48d5459a-da16-42a4-b502-60b173b764a5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

David Golden

unread,
Mar 17, 2017, 11:08:26 AM3/17/17
to mongodb-user
That's shell documentation, so I don't know, but I'll open a ticket about it.
Reply all
Reply to author
Forward
0 new messages