gpt4 book ai didi

node.js - 缺少架构错误 : Schema hasn't been registered for model during populate

转载 作者:太空宇宙 更新时间:2023-11-04 01:23:58 24 4
gpt4 key购买 nike

我有两个模型

1.PageType模型

module.exports = (mongoose) => {
const pageTypeSchema = new mongoose.Schema({
title: {
type: String,
key: {
type: String,
required: true,
},
}, {
timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
});
return mongoose.model('PageType', pageTypeSchema);
};
  • 工作流程模型
  •     module.exports = (mongoose) => {
    const workFlowSchema = new mongoose.Schema({
    title: {
    type: String,
    default: null,
    },
    key: {
    type: String,
    default: null,
    },
    level: {
    type: Number,
    required: true,
    },
    page_type_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'PageType',
    },
    }, {
    timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
    });
    return mongoose.model('WorkFlow', workFlowSchema);
    };

    但是当我尝试使用填充时,它会抛出Schema尚未为模型注册PageType

    async getFlowById(flowId) {
    const result = await this.workFlow.findById(flowId).populate('page_type_id').exec();
    return result;
    }

    有人可以帮我解决这个问题吗?
    在app.js中,模型包含在路由之前,PageType模型也在WorkFlow模型之前声明

    最佳答案

    您输入了错误的集合名称。集合名称是 Workflow,您正在尝试在工作流中 findById。所以我认为工作流程应该在那里。就这样试试吧。

    关于node.js - 缺少架构错误 : Schema hasn't been registered for model during populate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58206378/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com