#include <iostream>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
int main() {
auto session = conn.start_session();
auto coll = conn["db"]["collection"];
auto result = coll.update_one(session,
make_document(kvp("_id", 1)),
make_document(kvp("$inc", make_document(kvp("x", 1)))));
std::cout << "Updated " << result->modified_count() << " documents" << std::endl;
options::find opts;
secondary.
mode(read_preference::read_mode::k_secondary);
auto cursor = coll.find(session, make_document(kvp(
"_id", 1)), opts);
}
}
Class representing a client connection to MongoDB.
Definition client.hpp:54
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:36
Class representing an instance of the MongoDB driver.
Definition instance.hpp:78
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:67
read_preference & mode(read_mode mode)
Sets a new mode for this read_preference.
read_preference()
Constructs a new read_preference with read_mode set to k_primary.
Class representing a MongoDB connection string URI.
Definition uri.hpp:42
std::string to_json(document::view view, ExtendedJsonMode mode=ExtendedJsonMode::k_legacy)
Converts a BSON document to a JSON string, in extended format.
The top-level namespace for mongocxx library entities.
Definition bulk_write.hpp:24