简体   繁体   中英

connect-mongo is not working if we use clusters

connect-mongo is not working for shared mongo clusters. We have added "connect-mongo": "^0.8.2" module in our application, added the below config details.

"mongoStore": {
        "url" : "user:password@server1:27400/zeta-sessions,server2:27400/zeta-sessions,server3:27400/zeta-sessions",
        "name" : "web-app",
        "secret": "secret",
        "cookie": {
            "path": "/",
            "httpOnly": true,
            "maxAge": 31556952000 // 1 year
        },
"options" : {
                        "server": { "poolsize": 5 }
                        ,"replset": {"rs_name": "zeta-po"}

        },
        "resave": true,
        "saveUninitialized": true,
        "store": null    // NB: this will be overlaid in our module
}

Also,

// ./lib/mongo-session.js
'use strict';

var session = require('express-session'),
    MongoStore = require('connect-mongo')(session);

/** Creates a Mongo-backed session store.
 *
 * @param {Object} [config] Configuration options for express-session and connect-mongo
 * @returns {Object} Returns a session middleware which is backed by Mongo
 */
module.exports = function (config) {
    // add the 'store' property to our session configuration
    config.mongoStore.store = new MongoStore(config.mongoStore);

    // create the actual middleware
    return session(config.mongoStore);
};

getting below errors while executing the service.

Possibly unhandled Error: Required MongoStore option `db` missing or is not a string.
    at buildUrlFromOptions (/app/home/appjs/zeta-demo/node_modules/connect-mongo/lib/connect-mongo.js:163:15)
    at new MongoStore (/app/home/appjs/zeta-demo/node_modules/connect-mongo/lib/connect-mongo.js:250:7)
    at module.exports (/app/home/appjs/zeta-demo/web/lib/mongo-session.js:14:31)
    at resolveImpl (/app/home/appjs/zeta-demo/node_modules/kraken-js/node_modules/meddleware/index.js:98:20)
    at resolve (/app/home/appjs/zeta-demo/node_modules/kraken-js/node_modules/meddleware/index.js:53:18)
    at register (/app/home/appjs/zeta-demo/

Please share your thoughts.

Maybe its a bit late but I also had a similar issue, and I was able to solve it by adding my IP address to the IP access list as it was explained in this issue . In you MongoDB Atlas user, go to Security -> Network Access and add your IP or just set it to be accessed by any IP.

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