简体   繁体   中英

How to find the subdocument via subdocument id in mongoose?

I want to find the subdocument in mongoose by subdocument id.

i am doing :

mainDoc.subDocFieldName.id(sudocId);

But it shows

'cannot find property id of undefined'

seems like mainDoc.subDocFieldName is undefined .

so how do i access the sub document.?

I solved this problem by :

mainDoc[subDocFieldName].id(sudocId);

Actually I was using subDocument array.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM