Defining the Quantity Schema

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].

Listing 28.4 cart_model.js-QuantitySchema: Defining a basic quantity schema for quantity of products in orders and the cart


28 var ProductQuantitySchema = new Schema({
29   quantity: Number,
30   product: [ProductSchema]
31 }, { _id: false });
32 mongoose.model('ProductQuantity', ProductQuantitySchema);


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.148.187