Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-1388

Corrupted output | bsoncxx::to_json

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 3.1.1
    • Fix Version/s: None
    • Component/s: BSON
    • Labels:
    • Environment:
      Windows 10 Pro (language: French-FR)
      Microsoft Visual Studio Community 2017 v. 15.2 Release
      Boost 1.64.0

      Description

      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.

        Attachments

        1. mongodb.png
          mongodb.png
          160 kB
        2. MongoDB.vcxproj
          8 kB

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: