Client doesn't reconnect if connection refused

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.1.16
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi. I'm writing a simple script that is meant to connect to mongo and insert some records.

      Here's what I came up with:

      var db; // shared connection
      var url = 'mongodb://localhost:27017/project'
      MongoClient.connect(url,

      { poolSize: 10, reconnectTries: 10, reconnectInterval: 1000 }

      , function(err, mongoClient) {
      if(err)

      { console.log('ERROR!'); throw err; }

      db = mongoClient;
      });
      // TODO mongoClient.close();

      My script starts up mongo and tries to connect immediately.
      It turns out that there's a delay between mongo startup and the point of time when it opens a socket connection.

      So my script fails with "Error: connect ECONNREFUSED 127.0.0.1:27017"

      Is it an expected behavior?
      I don't believe that it can't recover from such an error.
      Maybe I don't understand something.

            Assignee:
            Christian Amor Kvalheim
            Reporter:
            John Yani
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: