我在sails.js config/connection.js
中有这个配置:
mongo: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: 'admin',
password: 'myPassword',
database: 'myDatabase',
schema: true
},
当我运行sails lift
时,我收到了以下错误:
error: A hook (`orm`) failed to load!
error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?
Error details:
{ [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
at _createError (/home/myuser/nodejs-tests/activityOverlord/node_modules/sails-mongo/lib/adapter.js:98:23)
at /home/myuser/nodejs-tests/activityOverlord/node_modules/sails-mongo/lib/adapter.js:101:13
at /home/myuser/nodejs-tests/activityOverlord/node_modules/sails-mongo/lib/connection.js:25:20
at /home/myuser/nodejs-tests/activityOverlord/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:457:15
at process._tickDomainCallback (node.js:381:11)
我有一个注册表单,可以将用户保存在MongoDB中,而不是将数据保存到" myDatabase"它将它保存到" admin"数据库我想使用我自己的数据库(它已经创建)
这是管理员用户保存到" admin"分贝:
{
"_id": "admin.admin",
"user": "admin",
"db": "admin",
"credentials": {
"MONGODB-CR": "b92c43a8b2da7f6275322fc4b2177424"
},
"roles": [
{
"role": "root",
"db": "admin"
}
]
}
希望有人能帮助我,谢谢大家!
答案 0 :(得分:0)
最后我可以做到......我需要一个dbOwner
用户
"roles": [
{
"role": "dbOwner",
"db": "myDatabase"
}
我使用mongo-express所以我需要另一个用户admin作为root
来控制UI中的所有内容
{
"_id": "admin.admin",
"user": "admin",
"db": "admin",
"credentials": {
"MONGODB-CR": "b92c43a8b2da7f6275322fc4b2177424"
},
"roles": [
{
"role": "root",
"db": "admin"
}
]
}
如果有人需要这样做,祝你好运