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

Cannot connect to replica set using C++ driver

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: legacy-1.0.5
    • Fix Version/s: None
    • Component/s: Release
    • Labels:

      Description

      When using legacy C++ driver, cannot connect to replica set servers. Although I can connect to every member separately with no problem. When multiple servers are specified in connection string, empty pointer is returned from cs.connect().

      Code snippet:
      #include <mongo/client/dbclient.h>
      #include <mongo/client/options.h>
      #include <mongo/client/init.h>
      #include <mongo/bson/bson.h>
      #include <iostream>
      #include <memory>
      #include <iostream>

      using namespace mongo;
      using namespace std;

      int main() {
      string rsName = "myProductionSet";
      string err;
      bool master;

      client::Options opt;
      client::initialize(opt);
      ConnectionString cs = ConnectionString::parse("mongodb://[host1]:27017,[host2]:27117/?replicaSet=myProductionSet",err);

      DBClientReplicaSet* client = static_cast<DBClientReplicaSet*>(cs.connect(err));
      if(!client)

      { cout << "Empty pointer" << endl; }

      if(client->isMaster(master))
      std::cout << "OK" << std::endl;
      else
      std::cout << "ERR" << std::endl;

      return 0;
      }

        Attachments

        1. mongod.conf
          0.9 kB
        2. mongod.log
          1 kB
        3. rsStatus.txt
          1 kB

          Activity

            People

            Assignee:
            adam.midvidy Adam Midvidy
            Reporter:
            peter123 Peter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: