在外壳中工作:
$ mongo -u monguser -p mongpass 192.168.2.2/ps --authenticationDatabase=admin
MongoDB shell version: 3.2.3
connecting to: 192.168.2.2/ps
Server has startup warnings:
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten]
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten]
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-02-23T01:59:10.522+0000 I CONTROL [initandlisten]
> db.foo.insert({can:'haz'})
WriteResult({ "nInserted" : 1 })
猫鼬失败:
'use strict';
const mongoose = require('mongoose');
const uri = 'mongodb://monguser:[email protected]:27017/ps'
console.log('mongoose.connect =', mongoose.connect(uri, (err) => {
err && console.log('err =', err);
}));
// For `mongoose.connect` output, see: https://gist.github.com/SamuelMarks/dedd863742f90cf2f333
err = { [MongoError: Authentication failed.]
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
code: 18,
errmsg: 'Authentication failed.' }
所以假设authenticationDatabase
需要以某种方式设置,也许在 config 参数中。 _语法是什么?_
最简单的方法是在 uri 中指定authSource
const uri = 'mongodb://monguser:[email protected]:27017/ps?authSource=admin';
谢谢
@vkarpov15你拯救了我的一天。 非常感谢。
有人知道在使用 mongodump 命令时如何指定 authSource 吗? :]
@ORESoftware mongodump 称之为authenticationDatabase
: https: //docs.mongodb.com/manual/reference/program/mongodump/#cmdoption -authenticationdatabase
最有用的评论
最简单的方法是在 uri 中指定
authSource
const uri = 'mongodb://monguser:[email protected]:27017/ps?authSource=admin';