将模式导入另一个文件

时间:2021-05-01 18:15:56

标签: node.js mongodb mongoose discord.js

我正在尝试将惩罚模式导入到我的 guild.js 中,但我不知道如何导入。

如你所见,我有惩罚.js,但我需要将惩罚模式包含到guild.js中,因为它依赖于它

Punishments.js

const mongoose = require("mongoose");

const punishmentType = Object.freeze({
  WARN: "Warn",
  BAN: "Ban",
  MUTE: "Mute",
});

const punishmentSchema = mongoose.Schema({
  userId: String,
  type: {
    type: String,
    enum: Object.values(punishmentType),
  },
});

exports.punishmentSchema = punishmentSchema;
exports.Punishment = mongoose.model("Punishment", punishmentSchema);

Guild.js

const mongoose = require("mongoose");

const guild = mongoose.Schema({
  id: String,
  prefix: String,
  punishments: [Punishment],
});

const Guild = mongoose.model("Guild", guild);
module.exports = Guild;

1 个答案:

答案 0 :(得分:0)

只是一个普通的require

const {Punishment} = require('./Punishments');
相关问题