c++ - 想要更新结果

标签 c++ mongodb

我正在更新一个集合:

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/

相关文章:

c++ - 如何启动内存有限的进程?

c++ - 如何检测丢失的字体字符

C++ 终止调用,没有事件异常

mongodb - 'bson.Decimal128'的MongoDump索引转换错误不支持

javascript - 尝试将参数从 View 传递到 Controller 方法

mongodb - 如何使用 MONGOLAB_URI 通过 mongo shell 连接到数据库?

在 Mac OS X Snow Leopard 上使用 Xcode 的 C++11

c++ - 为什么类成员的类型推导失败?

javascript - 找不到路线/发布/添加

ruby-on-rails - 如何使用 Mongoid 或 Mongo Ruby 驱动程序从 Ruby 代码获取 MongoDB 版本?