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

Cannot connect to replica set using C++ driver

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

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

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

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

              Created:
              Updated:
              Resolved: