Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2158

Cannot connect to MongoDB with replication that is using Unix socket

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: Not Applicable
    • Component/s: None
    • Labels:
    • Environment:
      Ubuntu 18.04, Node.JS v8.16.1

      Create a new mongodb with replication

      mongod --dbpath /home/lamp/mongotest --replSet rs01
      

      Initialize replication in mongo shell with Unix socket

      rs.initiate(\{_id:"rs01",version:1,members:[{_id:0,host:"/tmp/mongodb-27017.sock"}]})
      

      npm install mongodb, open node repl and try connecting to MongoDB with the driver, with replication.

      require("mongodb").MongoClient.connect("mongodb://%2Ftmp%2Fmongodb-27017.sock?replicaSet=rs01",console.log)
      

      An error is thrown

       MongoError: no primary found in replicaset or invalid replica set name
       at /home/lamp/mongotest/node_modules/mongodb/lib/core/topologies/replset.js:616:11
       at Server.<anonymous> (/home/lamp/mongotest/node_modules/mongodb/lib/core/topologies/replset.js:338:9)
       at Object.onceWrapper (events.js:315:30)
       at emitOne (events.js:116:13)
       at Server.emit (events.js:211:7)
       at Pool.<anonymous> (/home/lamp/mongotest/node_modules/mongodb/lib/core/topologies/server.js:377:12)
       at emitTwo (events.js:126:13)
       at Pool.emit (events.js:214:7)
       at connect (/home/lamp/mongotest/node_modules/mongodb/lib/core/connection/pool.js:624:10)
       at callback (/home/lamp/mongotest/node_modules/mongodb/lib/core/connection/connect.js:109:5) 
      

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            ledlamp89@gmail.com Lamp Lamp
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: