如何在我的猫鼬模式中引用多个模式?

问题描述 投票:1回答:1

我正在创建一个网站,您可以在其中进行和上传测试。因此,有两种用户:公司(上传测试)和候选人(参加测试)。现在,当我创建令牌时,如何同时引用架构(公司架构和候选人架构)?

const mongoose = require("mongoose");
const { ObjectId } = mongoose.Schema.Types;

let tokenSchema = new mongoose.Schema({
  userId: { type: ObjectId, ref: "<?>" }
});

module.exports = mongoose.model("Token", tokenSchema);
node.js express mongoose mongoose-schema mongoose-populate
1个回答
0
投票

让我们坐下来,这是您导出候选人和公司架构的方式:

module.exports = mongoose.model("Candidate", candidateSchema)

module.exports = mongoose.model("Company", companySchema)

您的令牌架构应类似于以下内容:

let tokenSchema = new mongoose.Schema(

candidateId: { type: ObjectId, ref: "Candidate" },

comoanyId:{ type: ObjectId, ref: "Company" },

);
© www.soinside.com 2019 - 2024. All rights reserved.