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
複製你正在做日誌的代碼的實際行,並在你的問題中顯示模式。 –