我正在更新一个集合:
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/