I am using mongoose to get person data from database. This is the code i use:
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);
}
});
});
This is output from console.log(result)
{ _id: 593c35e6ed9581db3ef85d75,
firstname: 'MyName',
lastname: 'MyLastName',
jobtitle: 'Web Developer',
email: '[email protected]',
githubLink: 'https://github.com/myGithub' }
And this is result from console.log(result.firstname); and console.log(result.githubLink);
MyName
undefined
Is this promise somehow messing up with this result? It's really weird because logging only the result shows my github link and logging the link says undefined.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…