如何在 SimpleSchema 中配置具有多个字段的唯一键
How to configure unique key with multiple field in SimpleSchema
我在 meteor 应用程序中使用 SimpleSchema。现在我需要定义具有多个字段的唯一键。在一个集合中,我有像
这样的字段
servingDate, vanId, timeSlot
我需要用这三个字段创建唯一字段。有没有可能在 SimpleSchema 中做?
您不能通过简单的模式配置来做到这一点。您唯一有效的选项是:
if (Meteor.isServer) {
MyCollection._ensureIndex(
{servingDate: 1, vanId: 1, timeSlot: 1},
{ unique: true }
);
}
我在 meteor 应用程序中使用 SimpleSchema。现在我需要定义具有多个字段的唯一键。在一个集合中,我有像
这样的字段servingDate, vanId, timeSlot
我需要用这三个字段创建唯一字段。有没有可能在 SimpleSchema 中做?
您不能通过简单的模式配置来做到这一点。您唯一有效的选项是:
if (Meteor.isServer) {
MyCollection._ensureIndex(
{servingDate: 1, vanId: 1, timeSlot: 1},
{ unique: true }
);
}