I have a problem with a javascript object returned from a mongo db, if I console.log the parent object, I see the child object, if console.log or use the child object, I get undefined
const templateResponse = await this.dbService.findbyCode(req); // <= here I get the parent object
console.log('EmailService -> getEmailCOntent -> templateResponse', templateResponse);
if (templateResponse) {
console.log('EmailService -> getEmailCOntent -> templateResponse6666', templateResponse.email);
}
EmailService -> sendMails -> emailContent
here I console.log parent and I see child email object:
{ _id: 5f5421eaa9248b90c815d80b,
email:
{ to: 'email@mail.com',
cc: '',
bcc: '',
subject: 'testttt',
body: 'this is a test',
from: 'no-reply@test.com' },
code: 'REQUESTOREMAILNOACCESS',
name: '',
description: '',
__v: 0
}
if I try to console.log child object I get undefined, I also tried templateResponse['email']
EmailService -> getEmailCOntent -> templateResponse.email
undefined
所以我通过在 mongo find 函数的末尾简单地添加 .lean() 来解决这个问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.