私のコードを見てください。私は検証エラーが発生していますが、私は正しい形式で私の文書を置くことを確信しています。マングース検証エラーですが、文書を正しく入れました
POSTMAN FROM MY MODEL
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;
});
});
MY JSONオブジェクト
{
"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"
}
の検索結果をやっていますか?私は立ち往生している。
? 'console.log(req.body)'のrsultを教えてください。 –
リクエストボディの結果を表示するために私の質問を編集しました –
注文をどのようにインポートしていますか?それらをvar Orderまたはvar orderに格納していますか? "Orders.create"を使ってください。 – rresol