如何创建一个复合索引,使一个帐户相同的 phone 编号两次?
How to create a compound index so that an account same phone number twice?
我正在尝试为我的用户帐户创建复合唯一索引。在我的架构中,我有 'category, email and phone number'。用户可以为不同的类别使用相同的电子邮件 ID,例如
example@example.com buyer
example@example.com seller
我通过以下几行实现了这一点 UserAccountSchema.index({userName: 1, userCategory: 1 }, { unique: true });
像这样我想要
example@example.com buyer 94xxxxxxx
example@example.com seller 94xxxxxxx
如何创建这样的复合唯一索引?
编辑现有索引并在其中添加 phoneNumber: 1
:
UserAccountSchema.index({userName: 1, userCategory: 1, phoneNumber: 1 }, { unique: true });
我正在尝试为我的用户帐户创建复合唯一索引。在我的架构中,我有 'category, email and phone number'。用户可以为不同的类别使用相同的电子邮件 ID,例如
example@example.com buyer
example@example.com seller
我通过以下几行实现了这一点 UserAccountSchema.index({userName: 1, userCategory: 1 }, { unique: true });
像这样我想要
example@example.com buyer 94xxxxxxx
example@example.com seller 94xxxxxxx
如何创建这样的复合唯一索引?
编辑现有索引并在其中添加 phoneNumber: 1
:
UserAccountSchema.index({userName: 1, userCategory: 1, phoneNumber: 1 }, { unique: true });