Search code examples
meteormeteor-collection2simple-schema

How to configure unique key with multiple field in SimpleSchema


I'm using SimpleSchema in meteor app. Now I need to define unique key with multiple field. In a Collection I have field like

servingDate, vanId, timeSlot

I need to make a unique with those three fields. Is there any possibilities to do in SimpleSchema ??


Solution

  • You cannot do that from with a simple schema configuration. Your only valid option is:

    if (Meteor.isServer) {
      MyCollection._ensureIndex(
        {servingDate: 1, vanId: 1, timeSlot: 1},
        { unique: true }
      );
    }