我有个模特
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)
}}
当我向邮递员发送邮件请求时,我会得到“所发送的物品的跟踪号码是必需的”错误。我做错什么了?
发布于 2022-03-18 07:40:39
好像你在请求中输入了错误。您已将itemstrackno标记为所需,但您正在发送itemtrackno
https://stackoverflow.com/questions/71523702
复制相似问题