Mongoose与其他数据有很多很多关系

时间:2015-02-23 08:42:12

标签: node.js mongodb mongoose

产品架构:

var ProductSchema = new Schema({
    productName: {type: String, required: true},
});

客户架构:

var ClientSchema = new Schema({
    clientName: {type: String, required: true},
    products: [{ type : mongoose.Schema.ObjectId, ref : 'Product'}],
});

如何在关系中添加其他字段?例如,添加字段数量

var ClientSchema = new Schema({
    clientName: {type: String, required: true},
    products: [{ type : mongoose.Schema.ObjectId, ref : 'Product', quantity: Number}],
});

0 个答案:

没有答案