#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;
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:58
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:79
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:37
find & read_preference(class read_preference rp)
Sets the read_preference for this operation.
find & max_time(std::chrono::milliseconds max_time)
Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
read_preference & mode(read_mode mode)
Sets a new mode for this read_preference.
Class representing a MongoDB connection string URI.
Definition: uri.hpp:43
std::string to_json(document::view view, ExtendedJsonMode mode=ExtendedJsonMode::k_legacy)
Converts a BSON document to a JSON string, in extended format.
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24