How to find the subdocument via subdocument id in mongoose?

蓝咒 提交于 2021-01-29 20:32:09

问题


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.?


回答1:


I solved this problem by :

mainDoc[subDocFieldName].id(sudocId);

Actually I was using subDocument array.



来源:https://stackoverflow.com/questions/18586391/how-to-find-the-subdocument-via-subdocument-id-in-mongoose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!