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

Cannot connect to exported mongo on docker

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 0
    • Not Needed

      What problem are you facing?

      I have a (single) mongo instance set as a replica set, to allow watch.

      It worked well with mongodb driver v3, but with v4 it fails. Tested with 4.4.2.

      What I found so far is that mongodb discovers its own hostname as "mongo" (which is set by Docker, so that's expected), but the connection is done to another address (10.1.2.3).

      The function updateServers in topology receives the incoming description with "mongo", then it replaces the attempted address with the received one, tries to connect to the new address (which fails), and destroys the previous connection.

      If I have a host named "mongo", but it is another host (unrelated to the one I tried to connect to), then I get:

      MongoServerSelectionError: Server selection timed out after 30000 ms

      If such a host doesn't exist, I get:

      MongoServerSelectionError: getaddrinfo ENOTFOUND mongo

      What driver and relevant dependency versions are you using?

      4.4.2

      Steps to reproduce?

      import * as mongodb from 'mongodb';
      const uri = 'mongodb://10.1.2.3/my-db';
      const client: mongodb.MongoClient = new mongodb.MongoClient(uri);
      client.connect()
        .then(() => {
          console.log('connected');
        },
        (err) => {
          console.error(err);
        });
      rs01:PRIMARY> rs.conf()
      {
              "_id" : "rs01",
              "version" : 2,
              "term" : 91,
              "protocolVersion" : NumberLong(1),
              "writeConcernMajorityJournalDefault" : true,
      
              "members" : [
                      {
                              "_id" : 0,
                              "host" : "mongo:27017",
                              "arbiterOnly" : false,
                              "buildIndexes" : true,
                              "hidden" : false,
                              "priority" : 1,
                              "tags" : {
      
                              },
                              "slaveDelay" : NumberLong(0),
                              "votes" : 1
                      }
              ],
              "settings" : {
                      "chainingAllowed" : true,
                      "heartbeatIntervalMillis" : 2000,
                      "heartbeatTimeoutSecs" : 10,
                      "electionTimeoutMillis" : 10000,
                      "catchUpTimeoutMillis" : -1,
                      "catchUpTakeoverDelayMillis" : 30000,
                      "getLastErrorModes" : {
      
                      },
                      "getLastErrorDefaults" : {
                              "w" : 1,
                              "wtimeout" : 0
                      },
                      "replicaSetId" : ObjectId("5ee64bfeb9fcf5482423f51d")
              }
      }

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            orgads@gmail.com Orgad Shaneh
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: