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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With