我正在尝试在我的 Schema 中创建一个文档,该文档本质上就像一个带有一组值(日期)的字典:
我想用它来跟踪我发送给用户的电子邮件通信:
let d = {
'generic-contact' = ['11/02/2019', '11/05/2020'],
'update-profile' = ['1/01/2018']
}
然后,我将使用以下内容更新此文档字段:
let emailAddresses = ['joebloggs@yahoo.com', 'foobar@googlemail.com']
let recipients = await Profile.find({ email: { "$in" : emailAddresses } })
let emailTopic = 'newsletter03'
recipients.forEach(user => {
user.correspondenceHistory[emailTopic].push(Date.now())
user.save()
})
我想这样做,以确保我不会在特定时间段内向同一用户发送相同的电子邮件。
但是我无法弄清楚如何在我的架构中进行设置。这种结构可能吗?
我尝试了许多不同的结构correspondenceHistory,但没有一个有效,我无法弄清楚我做错了什么。这是我的架构:
const mongoose = require("mongoose");
const passportLocalMongoose = require("passport-local-mongoose");
var profileSchema = new mongoose.Schema({
email: String,
firstname: String,
lastname: String,
correspondenceHistory: { type: Array } ### Here ###
}, { discriminatorKey: 'accountType', retainKeyOrder: true, timestamps: true });