mongocxx c++11 master driver document update

64 views
Skip to first unread message

Evan

unread,
Sep 16, 2015, 7:36:06 PM9/16/15
to mongodb-user
How can I update a document using the "_id" field? I can do it using another field, but not the "_id". I understand this field is an ObjectId, but how do I create a filter for it? Some code is below. Thanks for any help!

    mongocxx::instance inst{};
    mongocxx::client conn{};
    auto db = conn["todos"];

    builder::stream::document filter;
    builder::stream::document update;

    //bsoncxx::oid myoid("55f32a05c330964d296e6a11");

    //THIS WORKS USING THE CATCHUP FIELD
    filter << "catchup" << false;
    // THIS DOES NOT WORK
    //filter << "_id" << "55f32a05c330964d296e6a11";
    // THIS DOES NOT WORK
    //filter << "_id" << myoid;

    update << "$set" << bsoncxx::builder::stream::open_document
            << "minhand" << 44 << bsoncxx::builder::stream::close_document;

    db["clockdials"].update_one(filter, update);

Evan

unread,
Sep 17, 2015, 11:33:59 AM9/17/15
to mongodb-user
I figured it out. You have to use the bsoncxx::v0::oid not the bsoncxx::oid

//This does not work
//bsoncxx::oid myoid("55f32a05c330964d296e6a11");
//This works
bsoncxx::v0::oid myoid("55f32a05c330964d296e6a11");
filter << "_id" << myoid;

Andrew Morrow

unread,
Sep 18, 2015, 5:03:02 PM9/18/15
to mongod...@googlegroups.com

That really shouldn't be necessary. The 'v0' you are naming there is an inline namespace intended to manage ABI compatibility. You should never need to explicitly mention it.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/a5d6e6b4-e4fa-4c69-ab7d-4cf4800a58a6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages