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.插入这样两条数据
4.最后得到的数据,children为空
我应该怎么改呢