问答

nest.js同一个document使用mongoose的populate失效,如何修改?

作者:admin 2021-04-22 我要评论

mongoose的populate查询同一个document里面的子项 1.nav.schema.ts @Schema()export class Nav extends Document { @Prop({ type: Types.ObjectId }) _id: Types...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

mongoose的populate查询同一个document里面的子项
1.nav.schema.ts

@Schema()
export class Nav extends Document {

  @Prop({ type: Types.ObjectId })
  _id: Types.ObjectId;

  @Prop({ required: true })
  path: string
  @Prop()
  name?: string
  @Prop()
  component?: string
  @Prop()
  redirect?: string
  @Prop({ type: [{ type: Types.ObjectId, ref: 'Nav' }] })
  children?: Nav[]
  @Prop()
  meta?: meta

}

2.navs.service.ts

async find() {
    return this.model.find({ children: { $ne: [] } })
      .populate('children')
      .exec()
  }

3.插入这样两条数据
image
4.最后得到的数据,children为空
image
我应该怎么改呢

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • nest.js同一个document使用mongoose的p

    nest.js同一个document使用mongoose的p

  • react native实现启动页显示app加载进

    react native实现启动页显示app加载进

  • vue中如何在{{}}引用短线命名的变量

    vue中如何在{{}}引用短线命名的变量

  • 求推荐微前端框架

    求推荐微前端框架

腾讯云代理商
海外云服务器