如何使用Mongoose仅过滤子文档数组?

时间:2019-03-01 10:44:27

标签: mongodb mongoose

我在Mongoose中有一个文档架构,如下所示:

const ChildSchema = { 
  ...,
  deletedAt: Date
};
const ParentSchema = {
  ...,
  children: [ChildSchema]
};

现在,我可以使用Parent.findById()找到上级文档,但我希望它对children数组进行过滤以使typeof child.deletedAt === 'undefined'

这种仅对子文档的过滤可能吗?还是我只需要在查询结果上写旧的children.find

0 个答案:

没有答案