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

Invalid json value returned

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I'm using the mongocxx (v3) driver in my project to store the app settings in the mongodb. While working in windows everything seems to work well. But now that i'm testing in linux i have noticed some problems that i cannot understand why are happening.

      i have the following function to retrieve the app settings:

       

       QJsonObject MongoDBManager::getProjectsSettings(QString appid,QString projectsname)
       {
       try {
       
       if(m_selectedDB.has_collection(projectsname.toStdString())==false){
          LOG_ERROR()<<"collection '"+projectsname+"' do not exist";
          return QJsonObject();
       }
       
       mongocxx::collection selectedCollection = m_selectedDB[projectsname.toStdString()];
       auto cursor =selectedCollection.find(document{} << "appid" << appid.toStdString() << finalize);
       
       // auto cursor = m_selectedCollection.find(document{} << "_id" << appid.toStdString() << finalize);
       for (auto &&doc : cursor) { 
          bsoncxx::builder::stream::document s;
          s << "x" << 1.0;
       
          std::cout<<"testing:" << bsoncxx::to_json(s) << std::endl;
          std::cout<<"doc:"<< bsoncxx::to_json(doc)<<std::endl;
      }
      

      the output:
      ....

      testing:{ "x" : 1.0 }
      doc:{ "_id" :

      { "$oid" : "5e94da26ef664e37b0d8d1e4" }

      , "appid" : "5ea8a4192483621670ffeb2b", "value" : 1,1000000000000000888 }

      [![In the database i have:][1]][1]

      [1]: https://i.stack.imgur.com/6eE8H.png

      ::tojson returns a string with a comma instead of a dot in the decimal separator witch obviously is an invalid JSON document.

      ... "value" : 1,1000000000000000888 }

      the workaround is to change my local to en_US, but shouldn't the returned string be independent of the locale?

            Assignee:
            samantha.ritter@mongodb.com Samantha Ritter (Inactive)
            Reporter:
            rui.sebastiao@dreamforit.com Rui Sebastiao
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: