使用Node.js将数据插入MongoLab中的MongoDB时出现以下错误。
错误:
err { MongoError: not authorized on fgdp to execute command { insert: "f_user_login", documents: [ { email: "a@gmail.com", password: "0d7f943d633e49fb06fe6c53acabe3c5", dob: "01-08-2017", created_date: "2017-08-01 19:05:28", updated_date: "2017-08-01 19:05:28", status: 0, token: "", _id: ObjectId('598083a27d8f73686c43a55a') } ], ordered: true, writeConcern: { w: 1 } }
at Function.MongoError.create (/opt/lampp/htdocs/heroku/FGDP/node_modules/mongodb-core/lib/error.js:31:11)
at /opt/lampp/htdocs/heroku/FGDP/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/opt/lampp/htdocs/heroku/FGDP/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at Connection.messageHandler (/opt/lampp/htdocs/heroku/FGDP/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket.<anonymous> (/opt/lampp/htdocs/heroku/FGDP/node_modules/mongodb-core/lib/connection/connection.js:319: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:548:20)
name: 'MongoError',
message: 'not authorized on fgdp to execute command { insert: "f_user_login", documents: [ { email: "a@gmail.com", password: "0d7f943d633e49fb06fe6c53acabe3c5", dob: "01-08-2017", created_date: "2017-08-01 19:05:28", updated_date: "2017-08-01 19:05:28", status: 0, token: "", _id: ObjectId(\'598083a27d8f73686c43a55a\') } ], ordered: true, writeConcern: { w: 1 } }',
ok: 0,
errmsg: 'not authorized on fgdp to execute command { insert: "f_user_login", documents: [ { email: "a@gmail.com", password: "0d7f943d633e49fb06fe6c53acabe3c5", dob: "01-08-2017", created_date: "2017-08-01 19:05:28", updated_date: "2017-08-01 19:05:28", status: 0, token: "", _id: ObjectId(\'598083a27d8f73686c43a55a\') } ], ordered: true, writeConcern: { w: 1 } }',
code: 13 }
我正在解释下面的代码。
var mongoJs=require('mongojs');
var mden = require('md5');
var dateTime = require('node-datetime');
var collections=['f_users','f_user_login'];
var MONGOLAB_URI="mongodb://user:*******%40@ds127153.mlab.com:27153/fgdp";
var db=mongoJs(MONGOLAB_URI,collections);
exports.userSignup=function(req,res){
var email=req.body.email;
var password=req.body.password;
var dob=req.body.dob;
var dt = dateTime.create();
var createdDate=dt.format('Y-m-d H:M:S');
var updateDate=dt.format('Y-m-d H:M:S');
var encryptPass=mden(password);
db.f_user_login.count({'email':email},function(err,docs){
if (docs > 0) {
var data={"statusCode": 409,"error": "Conflict","message": "A user with this email exist. Please use different email."};
res.send(data);
}else{
var data = {
email: email,
password: encryptPass,
dob:dob,
created_date:createdDate,
updated_date:updateDate,
status:0,
token:''
};
db.f_user_login.save(data,function(err,docs){
if(!err){
if(docs){
res.send(docs);
}
}else{
console.log('err',err);
res.send('could not inserted');
}
})
}
})
}
这里我通过console
收到错误消息。在这里,我需要将数据插入数据库。
答案 0 :(得分:0)
当您无法对monogDB的数据库进行身份验证时,会抛出该错误。检查用户名和密码,并尝试使用带有这些凭据的shell登录。