| 1234567891011121314151617181920212223242526272829 |
- var Schema = require('mongoose').Schema;
- const taskSchema = new Schema({
- uuid: {
- type: String,
- required: true,
- index: true // 为 uuid 字段创建索引以提高查询性能
- },
- art: {
- type: String,
- required: true,
- index: true // 为 art 字段创建索引以提高查询性能
- },
- tasks: { // 存储 number 数组
- type: [Number], // 定义为数字数组
- default: [] // 默认值为空数组
- },
- createdAt: {
- type: Date,
- default: Date.now
- }
- });
- // 为 uuid 和 art 字段创建复合唯一索引
- // 这确保了 uuid 和 art 的组合是唯一的,如果尝试插入重复的组合会报错
- taskSchema.index({ uuid: 1, art: 1 }, { unique: true });
- module.exports = taskSchema;
|