0

I see solution here: Creating Multifield Indexes in Mongoose / MongoDB

How about 3、4、5... fields?

Here is my coffeescript code:

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}

And this works:

selectRecordSchema.index { srcSysId: 1, desSysId: 1}, { unique: true }
Community
  • 1
  • 1
J22Melody
  • 205
  • 1
  • 2
  • 8

1 Answers1

0

There is no limit for field count ( while you are not hitting something like memory limit, max doc size is 16MB )

mySchema.index({field1: 1, field2: 1, field3: 1, field4: 1, field5: 1, field6: 1}, {unique: true});
Adrian Toma
  • 547
  • 2
  • 13