samedi 2 avril 2016

mongoDB c++11 Driver get ID of inserted Document

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

Aucun commentaire:

Enregistrer un commentaire