Erro de validação de mangusto, mas eu coloquei os documentos corretamente
Por favor, dê uma olhada no meu código. Estou tendo um erro de validação, mas tenho certeza de que coloquei meus documentos no formato correto.
MEU MODELO
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var orderSchema = new Schema({
userPurchased: { type: Schema.Types.ObjectId, ref: 'users' },
products: [
{
product: { type: Schema.Types.ObjectId, ref: 'products' },
size: { type: String, required: true },
quantity: { type: Number, required: true },
subTotal: { type: Number, required: true }
}
],
totalQuantity: { type: Number },
totalPrice: { type: Number },
otherShipAd: { type: String },
modeOfPayment: { type: String },
paidStatus: {type: Boolean, default: false}
});
module.exports = mongoose.model('orders', orderSchema);
MY ROUTE
ordersRouter.route('/placeOrder')
.post(function (req, res) {
var body = req.body;
console.log(req.body);
var orderItem = {
userPurchased: body.userId,
products: [{
product: body._id,
size: body.size,
quantity: body.quantity,
subTotal: body.subTotal
}],
totalQuantity: body.totalQuantity,
totalPrice: body.totalPrice,
otherShipAd: body.customAdd,
modeOfPayment: body.modeOfPayment
};
Orders.create(orderItem, function (err, result) {
if (err) throw err;
});
});
MEU OBJETO JSON DA POSTMAN
{
"userPurchased": "5887f303c58a953360fe2759",
"products": [{
"product": "58466e8e734d1d2b0ceeae00",
"size": "m",
"quantity": 3,
"subTotal": 1197
},
{
"product": "58466e8e734d1d2b0ceeae00",
"size": "l",
"quantity": 3,
"subTotal": 1197
}],
"totalQuantity": 6,
"totalPrice": 2394,
"otherShipAd": "",
"modeOfPayment": "BDO"
}
Por favor, veja meu rastreamento de pilha de erros
O que estou fazendo de errado aqui? Estou preso.