为什么我无法使用nodejs在mongodb中创建。 我可以使用mongo shell插入数据。 但是如果我使用带有mongoose的nodejs插入数据。有一个错误。
{ MongoError: not authorized on node-angular to execute command { insert: "users", documents: [ { firstName: "Angelo", lastName: "Castillo", password: "password", email: "asdad@gmail.com", _id: ObjectId('59d
70936284aad66d4d1207b'), messages: [], __v: 0 } ], ordered: false }
at Function.MongoError.create (C:\Users\Desktop\Angular\Training\mean\node_modules\mongodb-core\lib\error.js:31:11)
at C:\Users\Desktop\Angular\Training\mean\node_modules\mongodb-core\lib\connection\pool.js:497:72
at authenticateStragglers (C:\Users\Desktop\Angular\Training\mean\node_modules\mongodb-core\lib\connection\pool.js:443:16)
at Connection.messageHandler (C:\Users\Desktop\Angular\Training\mean\node_modules\mongodb-core\lib\connection\pool.js:477:5)
at Socket.<anonymous> (C:\Users\Desktop\Angular\Training\mean\node_modules\mongodb-core\lib\connection\connection.js:331:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
name: 'MongoError',
message: 'not authorized on node-angular to execute command { insert: "users", documents: [ { firstName: "test", test: "lastname", password: "password", email: "asdad@gmail.com", _id: ObjectId(\'59d7
0936284aad66d4d1207b\'), messages: [], __v: 0 } ], ordered: false }',
ok: 0,
errmsg: 'not authorized on node-angular to execute command { insert: "users", documents: [ { firstName: "test", test: "Castillo", password: "password", email: "asdad@gmail.com", _id: ObjectId(\'59d70
936284aad66d4d1207b\'), messages: [], __v: 0 } ], ordered: false }',
code: 13,
codeName: 'Unauthorized' }
这是我在node-angular db中的用户。
> show users
{
"_id" : "node-angular.nodeangular",
"user" : "nodeangular",
"db" : "node-angular",
"roles" : [
{
"role" : "dbOwner",
"db" : "node-angular"
},
{
"role" : "readWrite",
"db" : "node-angular"
}
]
}