Skip to main content

Posts

Showing posts with the label Unique index

When NOT to use MongoDB background unique indexing

This is based on my personal experience working on MongoDB with a Java app. My Java app is a Springboot app using Spring Data MongoDB to connect with the database. And here is the maven dependency that I used. <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-data-mongodb </artifactId> </dependency> Before jumping into the problem, let me just brief about the indexes that we are using here. Indexes Indexes are set to a collection because, during my operations, I might need the collections to be queried based on these indexed fields faster and efficiently. Unique index : This could be a field that is unique for each document that you are saving in the collection. This field can be a Candidate key which would be a field where you could use to uniquely identify a document. Sometimes these indexes are created as a validation in the database level. So, you cannot insert two similar re...