【发布时间】:2020-08-01 23:36:33
【问题描述】:
我想创建一个基于具有猫鼬数据库背景的 nodejs 服务器的鸡尾酒 API。 API 将返回带有配方的鸡尾酒 我有一个包含鸡尾酒、用户和配料的工作原型。 我的问题是如何实现成分的数量?如果我例如。想要使用 2cl 的成分或 1 汤匙,我将如何在我的方案中实现这一点?
鸡尾酒模式
const schema = new Schema({
name: { type: String, required: true },
recipe: {type: String, required: true },
ingredients: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Ingredient'
}],
creator: {
type: mongoose.Schema.Types.ObjectId,
ref:'User'
},
createdDate: { type: Date, default: Date.now }
});
用户模式
const schema = new Schema({
username: { type: String, unique: true, required: true },
hash: { type: String, required: true },
email: { type: String, required: true },
favoriteCocktails:[{
type: Schema.Types.ObjectId,
ref: "Cocktail"
}],
createdDate: { type: Date, default: Date.now }
});
成分模式
const schema = new Schema({
name: { type: String, required: true },
alcoholic: { type: Boolean, required: true },
description: {type: String, required: false},
createdDate: { type: Date, default: Date.now }
});
我正在考虑在成分变量的鸡尾酒模式中添加一个字符串。我将如何实现这一点? 非常欢迎任何有关如何执行此操作或改进此操作的帮助提示
【问题讨论】:
标签: node.js api mongoose mongoose-schema