简体   繁体   中英

Reconnect MongoDB using MongoSkin ( Nodejs )

I have been using MongoSkin( Nodejs ) plugin to connect Mongodb as below.

    var db = mongo.db(dbconfig.mongo_ip+'/'+dbconfig.mongo_db_name);
    db.collection('myprofile').findOne({_id:memberid}, function(err, session){

        if(err){
            db.close();
            console.log(err.stack);
        }

    })

If i got the mongo connection error from node.js, then how do i reconnect the same using mongoskin,

Mongo Connect errr: Error: failed to connect to [localhost:27017]
    at [object Object].<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:184:51)
    at [object Object].emit (events.js:45:17)
    at [object Object].<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:110:14)
    at [object Object].emit (events.js:45:17)
    at Socket.<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:301:10)
    at Socket.emit (events.js:42:17)
    at Array.33 (net.js:799:27)
    at EventEmitter._tickCallback (node.js:108:26)

Please help me on this.

A good place to start is

https://github.com/kissjs/node-mongoskin/blob/master/test/db.js

but I assume you need to call open on db under mongoskin as well as in the driver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM