CNode

mongoose自引用不起作用呢?

问答
Ssuntopo发布于9 年前最后回复9 年前0 回复4754 浏览0 收藏
const ClazzSchema = new Schema({
    name: String,//班级名称,初一二班
    school: {
        type: ObjectId,
        ref: 'School'
    },//学校字段做冗余,方便查询
    virtual: Boolean,//是否为虚拟班级
    type: Number,//1理科,2文科,3艺体
    upgrade: {
        type: ObjectId,
        ref: 'Clazz'
    },//升级方向
    subClazz: {
        type: String,
        ref: 'Clazz'
    },//当前绑定的虚拟绑架
    parentClazz: {
        type: ObjectId,
        ref: 'Clazz'
    },//绑定的实体班级,虚拟班级失效后,该字段不删除
    grade: {
        type: ObjectId,
        ref: 'Grade'
    },
    status: Boolean,
    createdAt: Date,
    updatedAt: Date
});

模型设计如上,通过clazz,在populate('subClazz'),都没有发射查询语句,google之有说type换成string或是this的,但是我都没有试成功

查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。
参与回复
登录后即可参与回复。登录