Articles → MONGODB → Unique Index In MongodbUnique Index In MongodbThis article describes how to create a unique index in MongoDB.Purpose The unique index makes sure that duplicate values are not inserted into the field.Syntax db.[collection.createIndex({field:1},{unique:true})Example Consider the following collection: -A new index is created in the name field.Output Once the index is created, insert a duplicate value of the name field. The error message then appears.Posted By - Karan Gupta Posted On - Friday, April 26, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
db.[collection.createIndex({field:1},{unique:true})
Query/Feedback