mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

MongoError: connection 3 to cluster0.mongodb.net:27017 closed

Open mholttech opened this issue 9 years ago • 6 comments

I'm currently running MongoDB 3.4, NodeJS v6.10.3 and Mongoose 4.9.5.

When trying to connect to a cluster hosted through MongoDB Atlas i'm getting the following error:

1|streamdo | MongoError: connection 5 to cluster0.mongodb.net:27017 closed
1|streamdo |     at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
1|streamdo |     at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
1|streamdo |     at Socket.g (events.js:292:16)
1|streamdo |     at emitOne (events.js:96:13)
1|streamdo |     at Socket.emit (events.js:188:7)
1|streamdo |     at TCP._handle.close [as _onclose] (net.js:497:12)
0|streamdo | MongoError: connection 3 to cluster0.mongodb.net:27017 closed
0|streamdo |     at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
0|streamdo |     at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
0|streamdo |     at Socket.g (events.js:292:16)
0|streamdo |     at emitOne (events.js:96:13)
0|streamdo |     at Socket.emit (events.js:188:7)
0|streamdo |     at TCP._handle.close [as _onclose] (net.js:497:12)
PM2        | App name:AppName id:1 disconnected
PM2        | App [AppName] with id [1] and pid [22300], exited with code [0] via signal [SIGINT]
PM2        | Starting execution sequence in -cluster mode- for app name:AppName id:1
PM2        | App name:AppName id:0 disconnected
PM2        | App [AppName] with id [0] and pid [22294], exited with code [0] via signal [SIGINT]
PM2        | Starting execution sequence in -cluster mode- for app name:AppName id:0
PM2        | App name:AppName id:0 online
PM2        | App name:AppName id:1 online
0|streamdo | Env: production Port: 443/undefined User: root DB: cluster0.mongodb.net:27017/AppName,cluster0-01.mongodb.net:27017/AppName,cluster0.mongodb.net:27017/AppName
1|streamdo | Env: production Port: 443/undefined User: root DB: cluster0.mongodb.net:27017/AppName,cluster0-01.mongodb.net:27017/AppName,cluster0.mongodb.net:27017/AppName
1|streamdo | MongoError: connection 3 to cluster0.mongodb.net:27017 closed
1|streamdo |     at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
1|streamdo |     at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
1|streamdo |     at Socket.g (events.js:292:16)
1|streamdo |     at emitOne (events.js:96:13)
1|streamdo |     at Socket.emit (events.js:188:7)
1|streamdo |     at TCP._handle.close [as _onclose] (net.js:497:12)
PM2        | App name:AppName id:1 disconnected
PM2        | App [AppName] with id [1] and pid [22314], exited with code [0] via signal [SIGINT]
0|streamdo | MongoError: connection 3 to cluster0.mongodb.net:27017 closed
0|streamdo |     at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
0|streamdo |     at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
0|streamdo |     at Socket.g (events.js:292:16)
0|streamdo |     at emitOne (events.js:96:13)
0|streamdo |     at Socket.emit (events.js:188:7)
0|streamdo |     at TCP._handle.close [as _onclose] (net.js:497:12)
PM2        | Starting execution sequence in -cluster mode- for app name:AppName id:1
PM2        | App name:AppName id:0 disconnected
PM2        | App [AppName] with id [0] and pid [22320], exited with code [0] via signal [SIGINT]
PM2        | Starting execution sequence in -cluster mode- for app name:AppName id:0

Here is my connection configuration:

mongo: {
    host: 'cluster0.mongodb.net:27017/f,cluster0.mongodb.net:27017/AppName,cluster0.mongodb.net:27017/AppName',
    options: {
        user: 'admin',
        pass: 'password',
        auth: {
            authdb: 'admin'
        },
        db: {
            native_parser: true,
            readPreference: "primaryPreferred"
        },
        server: {
            ssl: true,
            slaveOk: true,
            auto_reconnect: true,
            socketOptions: {
                keepAlive: 5,
                connectTimeoutMS: 10000,
                socketTimeoutMS: 10000
            },
            readPreference: "primaryPreferred"
        },
        replset: {
            rs_name: 'Cluster0-shard-0',
            readPreference: "primaryPreferred",
            ha: true,
            socketOptions: {
                keepAlive: 5,
                connectTimeoutMS: 10000,
                socketTimeoutMS: 10000
            }
        }
    }
},

mholttech avatar May 09 '17 22:05 mholttech

Your uri format is incorrect. Use 'mongodb://cluster0.mongodb.net:27017,cluster1.mongodb.net:27017,cluster2.mongodb.net:27017/AppName' instead.

vkarpov15 avatar May 15 '17 22:05 vkarpov15

i'm still getting the error

MongoError: connection 3 to cluster0-shard-00-01-uuid.mongodb.net:27017 closed
    at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
    at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:497:12)
Env: production Port: 443/undefined User: root DB: mongodb://cluster0-shard-00-00-uuid.mongodb.net:27017,cluster0-shard-00-01-uuid.mongodb.net:27017,cluster0-shard-00-02-uuid.mongodb.net:27017/AppName
MongoError: connection 5 to cluster0-shard-00-00-uuid.mongodb.net:27017 closed
    at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
    at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:497:12)
Env: production Port: 443/undefined User: root DB: mongodb://cluster0-shard-00-00-uuid.mongodb.net:27017,cluster0-shard-00-01-uuid.mongodb.net:27017,cluster0-shard-00-02-uuid.mongodb.net:27017/AppName
MongoError: connection 3 to cluster0-shard-00-02-uuid.mongodb.net:27017 closed
    at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
    at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:497:12)
Env: production Port: 443/undefined User: root DB: mongodb://cluster0-shard-00-00-uuid.mongodb.net:27017,cluster0-shard-00-01-uuid.mongodb.net:27017,cluster0-shard-00-02-uuid.mongodb.net:27017/AppName
MongoError: connection 3 to cluster0-shard-00-01-uuid.mongodb.net:27017 closed
    at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
    at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:497:12)
Env: production Port: 443/undefined User: root DB: mongodb://cluster0-shard-00-00-uuid.mongodb.net:27017,cluster0-shard-00-01-uuid.mongodb.net:27017,cluster0-shard-00-02-uuid.mongodb.net:27017/AppName
MongoError: connection 5 to cluster0-shard-00-00-uuid.mongodb.net:27017 closed
    at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
    at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:497:12)
Env: production Port: 443/undefined User: root DB: mongodb://cluster0-shard-00-00-uuid.mongodb.net:27017,cluster0-shard-00-01-uuid.mongodb.net:27017,cluster0-shard-00-02-uuid.mongodb.net:27017/AppName
MongoError: connection 4 to cluster0-shard-00-00-uuid.mongodb.net:27017 closed
    at Function.MongoError.create (/opt/AppName/node_modules/mongodb-core/lib/error.js:29:11)
    at Socket.<anonymous> (/opt/AppName/node_modules/mongodb-core/lib/connection/connection.js:202:22)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:497:12)
Env: production Port: 443/undefined User: root DB: mongodb://cluster0-shard-00-00-uuid.mongodb.net:27017,cluster0-shard-00-01-uuid.mongodb.net:27017,cluster0-shard-00-02-uuid.mongodb.net:27017/AppName

mholttech avatar May 16 '17 00:05 mholttech

What does the code that's printing out these errors look like?

vkarpov15 avatar May 18 '17 01:05 vkarpov15

Please check IP whitelist or firewall. My case by default Atlas mongodb allowed only my PC's IP. Hence blocked from AWS.

lrnfrmHome avatar Dec 20 '17 04:12 lrnfrmHome

Navigate to setting add your system IP address on the white-list section. Solved.

delino12 avatar Mar 02 '18 19:03 delino12

White list all IPs, IPs life matter :p

x5engine avatar Nov 13 '18 21:11 x5engine