sql >> Base de Datos >  >> NoSQL >> MongoDB

Probando el controlador mongocxx c++ con un código de muestra

Dice lo que dice inicializó su controlador primero. si ha compilado su controlador correctamente, estos códigos deben estar funcionando.

   #include <cstdlib>
   #include <iostream>
   #include <bsoncxx/builder/stream/document.hpp>
   #include <bsoncxx/json.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/uri.hpp>


   using bsoncxx::builder::stream::close_document;
   using bsoncxx::builder::stream::document;
   using bsoncxx::builder::stream::finalize;
   using bsoncxx::builder::stream::open_document;
   mongocxx::instance instance{};// don't put inside main 

int main() {
mongocxx::client conn{ mongocxx::uri{ "mongodb://localhost:27017" } };
auto coll = conn["test"]["coll"];
bsoncxx::builder::stream::document document{};
document << "Data" << "hello";
coll.insert_one(document.view());

return 0;
}