New to MongoDB, I have followed the official instructions (https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/) to install MongoDB C driver then the last version of MongoDB C++ driver on Windows 10 Pro with MVS 15 2017 Win64.
My first project (the offical example code) compiles. However, the output is corrupted. I have explained my issue here: https://groups.google.com/forum/#!topic/mongodb-user/KxN5llw86Vc
The code:
#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["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
The same issue appears with this code:
#include <iostream>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/json.hpp>
int main(int, char**) {
bsoncxx::builder::basic::document doc{};
doc.append(bsoncxx::builder::basic::kvp("test", 1));
std::cout << bsoncxx::to_json(doc) << std::endl;
}
A Stackoverflow user has a similar issue: https://stackoverflow.com/questions/40309483/bsoncxxto-json-return-corrupted-string/40310414
I have tried different MVS configurations with no success.