Reputation: 51
I get this error when trying to connect with MongoClient.connect, but only when I'm offline. As soon as I'm online, with no change in code and not even restarting mongoDB, my app connects every time.
AssertionError: null == { MongoError: failed to connect to server [localhost:27017] on first connect
My server.js looks like this:
// server.js
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var operations = require('./operations');
// Connection URL
var url = 'mongodb://localhost:27017/myApp';
// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
assert.equal(null, err);
...
If I just use > mongo in the terminal, it connects with no problem even when offline. Did I miss something in the documentation?
Upvotes: 4
Views: 7551
Reputation: 51
Sorry! Only after I posted did Mongoose can't connect without internet appear in the related questions sidebar - not that I'm using Mongoose, but the answer exactly solved my problem also.
Upvotes: 1