Skip to content

Instantly share code, notes, and snippets.

@rcarloslima
Created November 16, 2018 22:11
Show Gist options
  • Save rcarloslima/6b95e4d469ae22f5ae327b12b14dc396 to your computer and use it in GitHub Desktop.
Save rcarloslima/6b95e4d469ae22f5ae327b12b14dc396 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
bsoncxx::builder::stream::document document{};
auto collection = conn["testedb"]["testecollection"];
document << "Mensagem" << "hello world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment