#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;
read_preference secondary;
secondary.mode(read_preference::read_mode::k_secondary);
auto cursor = coll.find(session, make_document(kvp("_id", 1)), opts);
for (auto&& doc : cursor) {
}
}
Class representing a client connection to MongoDB.
Definition: client.hpp:54
Class representing an instance of the MongoDB driver.
Definition: instance.hpp:78
Class representing a MongoDB connection string URI.
Definition: uri.hpp:42
class read_preference read_preference() const
Returns the read preference from the uri.
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