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

瀏覽次數:39 次
跳到第一則未讀訊息

Sumanta Dutta

未讀,
2017年3月15日 晚上7: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日 上午9: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日 上午8: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日 上午9: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 則新訊息