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

已查看 38 次
跳至第一个未读帖子

Sumanta Dutta

未读,
2017年3月15日 19:35:322017/3/15
收件人 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

未读,
2017年3月16日 09:12:052017/3/16
收件人 mongodb-user
Hi.

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

Regards,
David

Sumanta Dutta

未读,
2017年3月16日 11:34:202017/3/16
收件人 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

未读,
2017年3月17日 08:56:202017/3/17
收件人 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

未读,
2017年3月17日 09:29:342017/3/17
收件人 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

未读,
2017年3月17日 11:08:262017/3/17
收件人 mongodb-user
That's shell documentation, so I don't know, but I'll open a ticket about it.
回复全部
回复作者
转发
0 个新帖子