Defining the Customer Schema
The final schema is the customer schema. Listing 28.6 shows the full application schema including the CustomerSchema on lines 42-48. The CustomerSchema contains a unique userid field to identify the customer and associate orders with the customer. This field would normally map to an authenticated session userid.
Notice that the shipping, billing, and cart are all nested schemas. That makes it simple to define the model. You will see that each of these is accessed in the JavaScript, using shipping[0], billing[0], and cart[0] array indexing. No cart object schema is necessary because it is inherently implemented by the array of ProductQuantitySchema subdocuments.
Listing 28.6 cart_model.js: Full application schema including ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access