我正在使用nodejs
,express
,mongodb
。而且我想保存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
},
]
}
此代码有效。但是,还有什么更好的方法可以更有效地保存数据?