[英]Mongoose referencing _id not working
This is my code for a login route, I am trying to call docs._id
but it gives me back null
.这是我的登录路由代码,我试图调用docs._id
但它给了我null
。 When I call just docs
it shows this on server side:当我只调用docs
它会在服务器端显示:
[ { _id: EX unique id, username: { user: 'EXUsername', search: 'exusername' }, pass: 'EXpassword', email: 'EXemail' } ]
I am really confused on why I can't call docs.pass
or docs._id
at all but docs
itself has stuff in it and I can call docs and it gives data back.我真的很困惑为什么我根本不能调用docs.pass
或docs._id
但docs
本身就有内容,我可以调用 docs 并返回数据。
my code in node.js:我在 node.js 中的代码:
router.post('/loginUser', function(req, res){
CheckingLogin(req.db, req.body.username, req.body.password, function(bool, docs){
if(bool && exists(docs)){
var err = false;
var handleError = function(e){
if(err){
err = true;
var eDoc = {};
eDoc.errorCode = 1;
eDoc.error = e;
console.log(eDoc);
}
}
/////problem here//////////////////////////////////
var userID = docs._id;
console.log(docs._id);
if(userID != null){
if(!err){
tokens.db = req.db;
tokens.refresher.create(userID, function(token){
console.log('in token refresher ' + docs);
res.send('1');
});
}else{
console.log('Token err = true');
}
}else{
console.log('Creator token = null');
res.send('0');
}
}else{
res.send('0');
}
});
});
嘿,它是一个对象数组,所以像这个docs[0]._id一样获取它,它对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.