node.js - 我在猫鼬模式中的模式车辆键不应该为空
问题描述
大家好(快递新手)我正在创建一个模式对象,其中键值为名称:字符串,车辆:数组,图像:字符串,内容:字符串,如下所示
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
}
我的问题是车辆不应该是空的......我需要帮助
解决方案
我不能评论你,但我认为问题不在提供的代码中。保存和检索数据时可能会缺少 {$push: {vehicles: req.body.vehicles}}。
推荐阅读
- python - Rasa Core - 获取最新消息、自定义操作
- c# - 与签名匹配的代码中的方法列表(C# VS 使用 Roslyn 或扩展)
- java - Java AWT Robot 将鼠标点击放置在屏幕上完全随机的位置 [视频说明]
- julia - 如何使用 NLsolve 求解“只有一维方程”
- python - Spacy:ner 识别的日期不正确
- javascript - 如果页面上最多 3 分钟没有操作,则在 20 秒内关闭 javascript 中的窗口
- swift - Swift - 创建一个菜单以从多个位置导航到同一个视图控制器
- wordpress - 简单:网站左下角的浮动图片
- google-apps-script - 我编写了一个脚本将文件复制到备份文件夹,但独立的 webapp 文件被复制到根目录
- java - 当黄瓜中的 scnario 失败时出现异常