Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js mongoose.com中的交叉表查询错误_Node.js_Mongodb_Express_Mongoose - Fatal编程技术网

Node.js mongoose.com中的交叉表查询错误

Node.js mongoose.com中的交叉表查询错误,node.js,mongodb,express,mongoose,Node.js,Mongodb,Express,Mongoose,我有两个收藏,有很多关系: const mongoose = require("mongoose"); const Schema = mongoose.Schema; const { userModel } = require("../../user/models/user.schema"); let TimesheetDataSchema; const TimesheetSchema = Schema({ managersComment:

我有两个收藏,有很多关系:

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const { userModel } = require("../../user/models/user.schema");

let TimesheetDataSchema;

const TimesheetSchema = Schema({
    managersComment: {
        type: String,
    },
    data: [{ type: Schema.Types.ObjectId, ref: 'TimesheetDataSchema' }]
});
TimesheetSchema.plugin(mongoosePaginate);
const timesheetModel = mongoose.model("Timesheet", TimesheetSchema);


TimesheetDataSchema = new Schema(
    {
        user: { type: Schema.Types.ObjectId, ref: userModel },
        parentId: { type: Schema.Types.ObjectId, ref: "TimesheetSchema" },
    },
    { timestamps: true }
);

TimesheetDataSchema.plugin(mongoosePaginate);
const TimesheetIndividualData = mongoose.model("TimesheetData", TimesheetDataSchema);

module.exports = { timesheetModel, TimesheetIndividualData };
TimesheetSchema
中,我将
TimesheetDataSchema
的ref保存在
数据数组中

插入操作正在成功运行,如下所示:

 {
    "_id" : ObjectId("60b3a6a2d9cf6a3500f51e26"),
    "data" : [ 
        ObjectId("60b3a6a2d9cf6a3500f51e28"), 
        ObjectId("60b3a6a2d9cf6a3500f51e29"), 
        ObjectId("60b3a6a2d9cf6a3500f51e2a"), 
        ObjectId("60b3a6a2d9cf6a3500f51e2b"), 
        ObjectId("60b3a6a2d9cf6a3500f51e2c")
    ],
    "__v" : 0
}
const result = await timesheetModel.find({ user: '607030ba3c82e235443db610' }).populate('data')
但是,当我尝试读取集合时,populate会给出如下错误:

 {
    "_id" : ObjectId("60b3a6a2d9cf6a3500f51e26"),
    "data" : [ 
        ObjectId("60b3a6a2d9cf6a3500f51e28"), 
        ObjectId("60b3a6a2d9cf6a3500f51e29"), 
        ObjectId("60b3a6a2d9cf6a3500f51e2a"), 
        ObjectId("60b3a6a2d9cf6a3500f51e2b"), 
        ObjectId("60b3a6a2d9cf6a3500f51e2c")
    ],
    "__v" : 0
}
const result = await timesheetModel.find({ user: '607030ba3c82e235443db610' }).populate('data')
我得到的错误是:

MissingSchemaError: Schema hasn't been registered for model "TimesheetDataSchema"
请帮助,无法解决此问题