Cut*_*Eye 5 document get mongodb c++11 mongo-cxx-driver
我正在使用新的c ++ 11 mongoDB驱动程序(不是旧版驱动程序).
我在插入新文档后试图在mongoDB中获取文档的"id".此ID位于返回值"retVal3"中.
struct core::v1::optional<mongocxx::v_noabi::result::insert_one> retVal3 = collection.insert_one(document.view());
Run Code Online (Sandbox Code Playgroud)
这是没有auto命令的操作.我希望Eclipse能够解决这个问题并帮助我从中获取ID.不工作.
调试时我可以看到ID.它保存在12字节数组中.以十六进制显示它显示ID.这个结构深入到这个结构中.
retVal3 ==> core::v1::impl::storage<mongocxx::v_noabi::result::insert_one, false> ==>
val ==> _generated_id ==> _b_oid ==> value ==> _bytes ==> _M_elems char [12]
Run Code Online (Sandbox Code Playgroud)
我不知道如何从这个结构/对象中获取这12个字节.它是一个对象吗?
是否存在功能?你知道另一种方法吗?
谢谢
auto retVal = db.insert_one(hey.view()); // Part where document is uploaded to database
bsoncxx::oid oid = retVal->inserted_id().get_oid().value;
std::string JobID = oid.to_string();
Run Code Online (Sandbox Code Playgroud)
我问了mongoDB团队.得到了这个有效的回应=).