0

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 ??

Zahed
  • 73
  • 2
  • 9

1 Answers1

3

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 }
  );
}
Serkan Durusoy
  • 5,447
  • 2
  • 20
  • 39
  • The code works fine and duplicate keys cause a validation error on save. How do you set the custom validation error message? – Saeed D. May 18 '17 at 07:15