如何在不降低规格的情况下每天保存更改的数据

时间:2019-10-02 06:40:12

标签: node.js mongodb

我正在使用nodejsexpressmongodb。而且我想保存Number数据并显示每日更改图表。

const DownloadCountLogSchema = mongoose.Schema({
    date: Date,
    downloadCount: Number
})

const schema = mongoose.Schema({
    downloadCount: {    type: Number,                   required: true,     default: 0                          },
    downloadCountLog: { type: [DownloadCountLogSchema], required: true                                          },
})

会是这样。

{
    downloadCount: 123,
    downloadCountLog: [
        {
            date: "ISODate("2019-10-01T00:00:00.000Z")",
            downloadCount: 4
        },
        {
            date: "ISODate("2019-10-02T00:00:00.000Z")",
            downloadCount: 60
        },
        {
            date: "ISODate("2019-10-03T00:00:00.000Z")",
            downloadCount: 119
        },
    ]
}

此代码有效。但是,还有什么更好的方法可以更有效地保存数据?

0 个答案:

没有答案