Reputation: 587
How to create a unique key on multiple columns in a collection in mongodb. like we use this ADD UNIQUE unique_index
(user
, email
, phonenumber
); in sql.
Upvotes: 4
Views: 5849
Reputation: 1176
Try something like this
db.members.createIndex( { groupNumber: 1, lastname: 1, firstname: 1 },
{ unique: true } )
Check this link for more information mongodb create unique index
Upvotes: 11