Error de validación de mangosta pero puse los documentos correctamente
Por favor, eche un vistazo a mi código. Tengo un error de validación pero estoy bastante seguro de que pongo mis documentos en el formato correcto.
MI 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);
Mi ruta
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;
});
});
MI OBJETO JSON DE 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 vea mi seguimiento de pila de errores
¿Qué estoy haciendo mal aquí? Estoy atascado.