我有一個模型
const FormDataSchema = new mongoose.Schema({...})
// the Shipping schema
const ShippingSchema = new mongoose.Schema({
itemstrackno : {
type: String,
minlength: [3, "Minimum characters for this field is 3"],
maxlength: [100, "Maximum characters for this field is 100"],
required: [true, "The Shipped item's tracking number is required"],
trim: true,
unique: true
},
formData: [FormDataSchema]
}, {timestamps: true})
const Shipping = mongoose.model("Shipping", ShippingSchema)
module.exports = Shipping
我的后控制器
// post a shipment
exports.postShipment = async (req, res, next) => {
const {itemstrackno, formdata} = req.body
try {
const trackedItem = await Shipping.findOne({itemstrackno})
if(trackedItem){
return next(new ErrorResponse("An Item with this track number exists", 400))
}
const shipment = await Shipping.create({itemstrackno, formdata})
res.status(200).json({
success: true,
data: shipment
})
} catch (error) {
next(error)
}
}
當我向郵遞員發送郵寄請求時,我收到“需要運送物品的跟蹤號”錯誤。我究竟做錯了什么?
郵遞員形象
uj5u.com熱心網友回復:
好像您的請求中有錯字。您已標記itemstrackno為必填,但您正在發送itemtrackno
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/446751.html
標籤:javascript 节点.js 猫鼬 邮政 邮差
