For orders and the shopping cart, you can include the products in an array. However, you also need to be able to store a quantity. One method of doing this is to define a quantity schema with quantity and product fields. Listing 28.4 implements ProductQantitySchema
, which does just that. Notice that because you are embedding ProductSchema
, you include it as an array, and throughout the example, you access it by using product[0]
.
28 var ProductQuantitySchema = new Schema({
29 quantity: Number,
30 product: [ProductSchema]
31 }, { _id: false });
32 mongoose.model('ProductQuantity', ProductQuantitySchema);