猫鼬模型属性枚举或参考

时间:2018-04-25 06:32:39

标签: mongodb mongoose mongoose-schema

我正在处理我的项目,我有一个与mongoose schema属性相关的问题。

以下是当前代码:

const CURRENCY = "EUR", "USD", "GBP";
let Salary = new Schema
({
    currency: { type: String, enum: CURRENCY, required: true },
    amount: number
});

问题是:如果我(也许)想要扩展此列表,哪种方式更好?使用上面的枚举或使用包含货币的其他架构?

像:

let Currency = new Schema
({
    currencyType: { type: String },
});

let Salary = new Schema
({
    currency: { type: mongoose.Schema.Types.ObjectId, ref: 'Currency' },
    amount: Number
});

是否经常只使用一个属性创建架构?

感谢您的帮助。

0 个答案:

没有答案
相关问题