如何通过mongoose中的子文档ID查找子文档? [英] How to find the subdocument via subdocument id in mongoose?

查看:56
本文介绍了如何通过mongoose中的子文档ID查找子文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过子文档id查找mongoose中的子文档

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

我在做:

mainDoc.subDocFieldName.id(sudocId);

但它显示

'cannot find property id of undefined'

似乎 mainDoc.subDocFieldNameundefined.

那么我如何访问子文档.?

so how do i access the sub document.?

推荐答案

我通过以下方式解决了这个问题:

I solved this problem by :

mainDoc[subDocFieldName].id(sudocId);

实际上我使用的是 subDocument 数组.

Actually I was using subDocument array.

这篇关于如何通过mongoose中的子文档ID查找子文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆