Node.js 无法在NodeJS服务工作者中填充mongoose架构模型
我正在进行MERN堆栈设置以及Mongoose和Typescript 我试图在NodeJS服务人员上运行一个简单的查询,以查找单个模型文档并填充其参考文档(标记) 但是,此查询在Express控制器中运行良好,但在服务工作者上运行不好 这是我的密码: 模式模型Node.js 无法在NodeJS服务工作者中填充mongoose架构模型,node.js,mongodb,express,mongoose,service-worker,Node.js,Mongodb,Express,Mongoose,Service Worker,我正在进行MERN堆栈设置以及Mongoose和Typescript 我试图在NodeJS服务人员上运行一个简单的查询,以查找单个模型文档并填充其参考文档(标记) 但是,此查询在Express控制器中运行良好,但在服务工作者上运行不好 这是我的密码: 模式模型 /** * Question Model */ export interface QuestionModel extends QuestionRecord, Document {} export const QuestionSchem
/**
* Question Model
*/
export interface QuestionModel extends QuestionRecord, Document {}
export const QuestionSchema: Schema = new Schema({
title: {
type: String,
required: true
},
type: {
type: String,
required: true
},
description: String,
tags: [{
type: Schema.Types.ObjectId,
ref: 'Tag'
}],
isDraft: {
type: Boolean,
default: true
}
}, {
timestamps: true
})
/**
* Tag Model
*/
export interface TagModel extends TagRecord, Document {}
export const TagSchema: Schema = new Schema({
key: {
type: String,
required: true
},
name: {
type: String,
required: true
}
}, {
timestamps: true
})
查询(在职员工)
错误
const question = await QuestionSchemaModel.findById(questionId, { title: 1, tags: 1, type: 1, description: 1 }).populate('tags');
console.log('Print Tags:', question.tags);
my-api | Worker for job "requeueExpired" had an error {
my-api | err: Error [MissingSchemaError]: Schema hasn't been registered for model "Tag".
my-api | Use mongoose.model(name, schema)
my-api | at NativeConnection.Connection.model (/usr/src/app/node_modules/mongoose/lib/connection.js:1255:11)
my-api | at getModelsMapForPopulate (/usr/src/app/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:301:59)
my-api | at populate (/usr/src/app/node_modules/mongoose/lib/model.js:4338:21)
my-api | at _populate (/usr/src/app/node_modules/mongoose/lib/model.js:4308:5)
my-api | at /usr/src/app/node_modules/mongoose/lib/model.js:4284:5
my-api | at promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
my-api | at Mongoose._promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/index.js:1135:10)
my-api | at Function.Model.populate (/usr/src/app/node_modules/mongoose/lib/model.js:4282:23)
my-api | at model.Query.Query._completeOne (/usr/src/app/node_modules/mongoose/lib/query.js:2078:9)
my-api | at Immediate.<anonymous> (/usr/src/app/node_modules/mongoose/lib/query.js:2117:10)
my-api | at Immediate.<anonymous> (/usr/src/app/node_modules/mquery/lib/utils.js:124:16)
my-api | at processImmediate (node:internal/timers:463:21)
my-api | }
my-api | Worker for job "requeueExpired" exited with code 1 undefined
my api |作业“RequeExpired”的工作人员出现错误{
my api | err:Error[MissingSchemaError]:尚未为模型“标记”注册架构。
我的api |使用mongoose.model(名称、模式)
我的api |位于NativeConnection.Connection.model(/usr/src/app/node_modules/mongoose/lib/Connection.js:1255:11)
我的api |位于getModelsMapForPopulate(/usr/src/app/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:301:59)
我的api | at populate(/usr/src/app/node_modules/mongoose/lib/model.js:4338:21)
我的api | at u填充(/usr/src/app/node_modules/mongoose/lib/model.js:4308:5)
我的api | at/usr/src/app/node_modules/mongoose/lib/model.js:4284:5
promiseOrCallback上的我的api(/usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
我的api |在Mongoose._PromiseCallback(/usr/src/app/node_modules/Mongoose/lib/index.js:1135:10)
我的api位于Function.Model.populate(/usr/src/app/node_modules/mongoose/lib/Model.js:4282:23)
我的api | at model.Query.Query._completeOne(/usr/src/app/node_modules/mongoose/lib/Query.js:2078:9)
我的api |立即启动。(/usr/src/app/node_modules/mongoose/lib/query.js:2117:10)
我的api |立即启动。(/usr/src/app/node_modules/mquery/lib/utils.js:124:16)
my api | at processImmediate(节点:内部/计时器:463:21)
我的api |}
我的api |工单“requeueExpired”退出,代码1未定义
感谢您的帮助,
提前谢谢 您是否尝试搜索错误消息?你也是这样吗:?