在Mongoose / MongoDB中创建多字段(2个以上)索引

Creating Multifield(more than 2) Indexes in Mongoose / MongoDB

本文关键字:2个 索引 字段 Mongoose MongoDB 创建      更新时间:2023-09-26

我看到了解决方案:在Mongoose/MongoDB中创建多字段索引

3、4、5……字段?

这是我的coffeescript代码:

selectRecordSchema = new Schema
  srcSysId: { type: String, required: true }
  desSysId: { type: String, required: true }
  stuId: { type: String, required: true }
  courseId: { type: String, required: true }
selectRecordSchema.index { srcSysId: 1, desSysId: 1,stuId: 1,courseId: 1 }, { unique: true}

selectRecordSchema.index { srcSysId: 1, desSysId: 1}, { unique: true }

字段数没有限制(当您没有达到内存限制时,最大文档大小为16MB)

mySchema.index({field1: 1, field2: 1, field3: 1, field4: 1, field5: 1, field6: 1}, {unique: true});