Next, you need to create the order schema to keep track of the items ordered, shipping information, and billing information. Listing 28.5 implements the OrderSchema
model, which stores the necessary information about the order. Notice that a Date
type is assigned to the timestamp
field to keep track of when the order was placed. Also, the items
field is an array of ProductQuantitySchema
subdocuments.
33 var OrderSchema = new Schema({
34 userid: String,
35 items: [ProductQuantitySchema],
36 shipping: [AddressSchema],
37 billing: [BillingSchema],
38 status: {type: String, default: "Pending"},
39 timestamp: { type: Date, default: Date.now }
40 });
41 mongoose.model('Order', OrderSchema);