0
我正在使用猫鼬从数据库中获取人员数据。这是我使用的代码:Mongoose模型对象行为奇怪
return new Promise((resolve, reject) => {
Person.findOne({}, (err, result) => {
if(err) {
reject(err);
} else {
console.log(result);
console.log(result.firstname);
console.log(result.githubLink);
resolve(result);
}
});
});
这是来自的console.log(结果)输出
{ _id: 593c35e6ed9581db3ef85d75,
firstname: 'MyName',
lastname: 'MyLastName',
jobtitle: 'Web Developer',
email: '[email protected]',
githubLink: 'https://github.com/myGithub' }
这是从的console.log(result.firstname)结果;和console.log(result.githubLink);
MyName
undefined
这个承诺是不知何故搞乱了这个结果?这真的很奇怪,因为只记录结果显示我的github链接并记录链接说未定义。
是你确定在任何地方都没有任何拼写错误? –
我已经从console.log(result)的输出复制并粘贴了“githubLink”,并且我一直在盯着这段代码30分钟。我不认为这是一个错字 – Frostbch
复制你正在做日志的代码的实际行,并在你的问题中显示模式。 –