schema-task.js 736 B

1234567891011121314151617181920212223242526272829
  1. var Schema = require('mongoose').Schema;
  2. const taskSchema = new Schema({
  3. uuid: {
  4. type: String,
  5. required: true,
  6. index: true // 为 uuid 字段创建索引以提高查询性能
  7. },
  8. art: {
  9. type: String,
  10. required: true,
  11. index: true // 为 art 字段创建索引以提高查询性能
  12. },
  13. tasks: { // 存储 number 数组
  14. type: [Number], // 定义为数字数组
  15. default: [] // 默认值为空数组
  16. },
  17. createdAt: {
  18. type: Date,
  19. default: Date.now
  20. }
  21. });
  22. // 为 uuid 和 art 字段创建复合唯一索引
  23. // 这确保了 uuid 和 art 的组合是唯一的,如果尝试插入重复的组合会报错
  24. taskSchema.index({ uuid: 1, art: 1 }, { unique: true });
  25. module.exports = taskSchema;