【发布时间】:2019-08-03 00:57:55
【问题描述】:
我正在构建一个 MEAN 堆栈 Web 应用程序, 我有两个相关的集合 categories 和 brands。
现在,当我添加一个新品牌并自动选择其类别时,类别 ID 会保存在品牌架构中, 但是当我从类别架构中删除类别时,我不知道如何更新(设置为空)此字段(品牌架构中的类别 ID)... 希望我把我的问题说清楚了。
const mongoose = require('mongoose');
const categorySchema = mongoose.Schema({
categoryname: { type: String, required:true},
categoryBrands: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Brand",
required: true }]
});
module.exports = mongoose.model('Category', categorySchema);
品牌集合架构:
const mongoose = require('mongoose');
const brandSchema = mongoose.Schema({
brandName: { type: String, required: true },
brandCategory: {
type: mongoose.Schema.Types.ObjectId,
ref: "Category",
required: true
}
});
module.exports = mongoose.model('Brand', brandSchema);
【问题讨论】:
标签: angularjs express mongoose mean-stack