首页 > 解决方案 > 我在猫鼬模式中的模式车辆键不应该为空

问题描述

大家好(快递新手)我正在创建一个模式对象,其中键值为名称:字符串,车辆:数组,图像:字符串,内容:字符串,如下所示

const Logistics = mongoose.model('Logistics', new mongoose.Schema({
name: {
    required: true,
    type: String,
    minlength: 3,
    maxlength: 300
},
image: {
    type: String,
    required: true
},
vehicles: {
    type: Array,
    required: true,
},
content: {
    type: String,
    required: true
}}))

当我通过邮递员发送帖子请求时,我得到了这个

{
"vehicles": [],
"_id": "604a011dxxxxxxxxxxxxxxxx",
"name": "Air Freight",
"image": "path",
"content": "940 AirCargo is a Freight Forwarder capable of handling your time-sensitive cargo. We forward Air shipments to every Corner of the globe on a daily basis, ranging from fresh produce to Europe and Americas to Project Equipments to Mining and Power Companies in the Great lakes region. In addition we avail Cargo capacity daily to world destinations through signing block space Agreements with scheduled cargo/passenger carriers to ensure that our solutions to clients are seamless.",
"__v": 0

}

我的问题是车辆不应该是空的......我需要帮助

标签: node.jsmongodbexpressmongoose

解决方案


我不能评论你,但我认为问题不在提供的代码中。保存和检索数据时可能会缺少 {$push: {vehicles: req.body.vehicles}}。


推荐阅读