【问题标题】:My schema vehicles key in mongoose schema should not be empty我在猫鼬模式中的模式车辆键不应该为空
【发布时间】:2021-03-23 03:24:36
【问题描述】:

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

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.js mongodb express mongoose


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-02-02
      • 1970-01-01
      • 2020-05-18
      • 2016-08-05
      • 2018-10-26
      • 2018-02-15
      • 2014-08-31
      • 2021-08-21
      • 2020-09-18
      相关资源
      最近更新 更多