sql >> Database teknologi >  >> NoSQL >> MongoDB

Tester mongocxx c++ driver med en prøvekode

Det siger, hvad der står, initialiserede din driver først. hvis du har kompileret din driver korrekt, skal disse koder virke.

#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; }

  1. MongoDB $skub

  2. MongoRepository findByCreatedAtBetween returnerer ikke nøjagtige resultater

  3. MongoDB ved hjælp af en OR-klausul i mongoengine

  4. MongoDB $acos