mongodb添加用户密码并进行配置

//mongodb设置用户名密码,在mongodb/bin目录下
use admin 
db.addUser('user12345','foobar'); 

app.use(session({
    store: new MongoStore({
        // Basic usage
        host: 'localhost', // Default, optional,可不写
        port: 27017, // Default, optional,可不写
        db: 'test-app', // Required

        // Basic authentication (optional)
        username: 'user12345',
        password: 'foobar',

        // Advanced options (optional)
        autoReconnect: true, // Default
        w: 1, // Default,
        ssl: false // Default
    })
}));
//或
app.use(session({
    store: new MongoStore({
        url: 'mongodb://user12345:foobar@localhost:27017/test-app?authSource=admins&w=1',
        mongoOptions: advancedOptions // See below for details
    })
}));

//mongoskin配置
server/config/webconfig.json
{
    "DB": "mongodb://user12345:foobar@localhost:27017/Mobile?auto_reconnect=true&poolSize=20",
    "isDev": false,
    "AppID": ["31272561859136d600f9983b52727e49", "0c23d039199c2ced25940656814d87dd"],
    "exporters":["xml","html","text","tabular"],
    "errorCode": {
        "user": [1, 100],
        "computer": [101, 200],
        "vendor": [201, 300]
    }
}

//linux下后台启动mongodb
mongod --fork --logpath /data/log/mongodb.log --logappend 

//远程登录数据库

//有密码时
mongo 10.3.19.31:62167/test -u 用户名 -p 密码

//没有用户名和密码验证的话,直接使用:
mongo 10.3.19.31:62167/test即可

//本地登录mongodb数据库,在mongodb/bin目录下,直接执行mongo


你可能感兴趣的:(数据库)