最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

MongoDB中插入空日期

运维笔记admin15浏览0评论

MongoDB中插入空日期

MongoDB中插入空日期

邮件架构:

var mail = new mongoose.Schema({
    globalId: {type: String, index: true, unique: true},
    from: {type: String, required: true},
    beginDate: {type: Date, required: true},
    endDate: {type: Date},
    source: {type: String},
    address: {type: String},
    subject: {type: String, required: true},
    text: {type: String},
    note: {type: String},
    files: [
        {
            fileName: {type: String},
            fileSize: {type: Number},
            fileType: {type: String}
        }
    ]
});

当我尝试保存新邮件与结束日期为空,我有以下错误

Mail validation failed: endDate: Cast to Date failed for value "null"
回答如下:

它看起来像你要保存的模式与一个无效的结束日期。

如果你不希望保存的日期只是离开它,从对象。比如你需要为你的模式至少是:

const newMail = mail.create({
    globalId: "1234",
    from: "Jack",
    begineDate: new Date(),
    subject: "Random subject",
});

如果你试图做这样的事情,

endDate: null

因为它是期待一个Date()对象或什么都没有,这将失败。

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论