I'm working with new c++11 mongoDB driver ( NOT the Legacy Driver ).
I'm trying to get the 'id' of a document in mongoDB after I inserted a new document. This ID is in the returned value 'retVal3'.
struct core::v1::optional<mongocxx::v_noabi::result::insert_one> retVal3 = collection.insert_one(document.view());
This is the operation with out the auto command. I hoped Eclipse would be able to resolve this and help me to get the ID out of it. Did not work.
While debugging I can see the ID. Its saved in a 12 Byte array. Displaying in hex it shows the ID. This arry is deep deep down in this struct.
retVal3 ==> core::v1::impl::storage<mongocxx::v_noabi::result::insert_one, false> ==>
val ==> _generated_id ==> _b_oid ==> value ==> _bytes ==> _M_elems char [12]
I do have no idea how to get those 12 Bytes out of this struct/object. Is it a object?
Is there a Function, which is existing? Do you know a other way to get it out?
Thx
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();
I asked the mongoDB team. got this working response =).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With