gpt4 book ai didi

c++ - 想要更新结果

转载 作者:太空宇宙 更新时间:2023-11-04 11:48:00 25 4
gpt4 key购买 nike

我正在更新一个集合:

conn->update("mycollection", BSON("_id" << ID), BSON("$set" << BSON("myfiled" << myvalue)));

有没有办法知道集合是否真的更新了? “update”函数无效,没有抛出异常。即使没有数据写入数据库,函数 GetLastError 也返回空字符串。

最佳答案

来自 MongoDB 文档:

Write concern describes the guarantee that MongoDB provides when reporting on the success of a write operation. The strength of the write concerns determine the level of guarantee. When inserts, updates and deletes have a weak write concern, write operations return quickly. In some failure cases, write operations issued with weak write concerns may not persist. With stronger write concerns, clients wait after sending a write operation for MongoDB to confirm the write operations.

我没有使用 C++ 驱动程序,但在 Java 驱动程序中有一个 WriteConcern允许您控制操作的类。您可以检查 C++ 驱动程序中的等效类。

有关 Write Concern 的更多信息,请查看 here .

关于c++ - 想要更新结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19320257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com