尝试使用MongoDB和Node.js登录用户时出现以下错误。
错误:
/opt/lampp/htdocs/FGDP/node_modules/mongodb/lib/mongo_client.js:236
throw err
^
Error: cyclic dependency detected
at serializeObject (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:296:33)
at serializeInto (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/opt/lampp/htdocs/FGDP/node_modules/bson/lib/bson/parser/serializer.js:776:17)
我正在解释下面的代码。
loginController.js:
var userData={'user_name':$scope.user_name,'user_pass':$scope.user_pass};
$http({
method: 'POST',
url: "/login",
data: userData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('login',response);
if(response.data['user_type']=='1'){
$location.path('dashboard');
}
},function errorCallback(response) {
console.log(response);
});
我的服务器端代码如下所示。
var mongoJs=require('mongojs');
var CryptoJS = require("crypto-js");
var database='FGDP';
var collections=['f_users'];
var db=mongoJs("127.0.0.1:27017/"+database, collections);
exports.userlogin=function(req,res){
var username=req.body.user_name;
var password=req.body.user_pass;
var ciphertext = CryptoJS.AES.encrypt(password, 'lexelPass');
db.f_users.findOne({login_name:username,password:ciphertext},function(err,docs){
if(!err){
if(docs){
req.session.email=docs.email;
req.session.name=docs.name;
req.session.login_name=docs.login_name;
req.session.status=docs.status;
req.session.user_type=docs.user_type;
res.send(docs);
}
}
if(err){
res.send("Login failed");
}
})
}
这里我在服务器端出现上述错误。请帮我解决这个问题。