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

时间:2014-05-26 12:54:37

标签: javascript node.js mongoose

我在这里看到解决方案: Creating Multifield Indexes in 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 }

1 个答案:

答案 0 :(得分:0)

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

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