【发布时间】:2019-01-14 03:50:12
【问题描述】:
我正在尝试配置猫鼬模式唯一参数。我需要每天允许写入数据库的唯一作者不超过一位。 Schema.index( { author: 1, created: 1 } , { unique: true} ) 不起作用,这里我无法输入时间段。
有什么更好的方式来决定这个案子?
const Report = new Schema({
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'DiscordUserList',
required: true
},
reports: [{ reportNum: { type: Number }, text: { type: String }, date: { type: Date, default: Date.now } }],
questionsDone: [{ questionNum: { type: Number }, done: { type: Boolean }, date: { type: Date, default: Date.now } }],
created: {
type: Date,
default: Date.now
}
}, { strict: false })
Report.plugin(mongoosePaginate)
const reportListSchema = mongoose.model('ReportList', Report)
module.exports = reportListSchema
【问题讨论】: