Please take a look at my code. I am having a validation error but I am quite sure that I put my documents on the correct format.
MY MODEL
You are doing mistake while creating a neworder
. Look at the contents
of req.body
and look what you are passing to the orders
object.
Try this:
var orderItem = new Orders();
orderItem.userPurchased=body.userId;
//for each products item, push it to orderItem.products
body.products.forEach(function(product,index)
{
orderItem.products.push({
product: product.product,
size: product.size,
quantity: product.quantity,
subTotal: product.subTotal
});
});
orderItem.totalQuantity=body.totalQuantity;
orderItem.totalPrice=body.totalPrice;
orderItem.otherShipAd=body.customAdd;
orderItem.modeOfPayment=body.modeOfPayment;
Orders.save(function (err, result) {
if (err) throw err;
});