Home > Mobile >  How can I save duplicate in Mongodb using springboot?
How can I save duplicate in Mongodb using springboot?

Time:12-15

I have to read the csv file and then save the content of the csv file in mongodb. While saving the data, if any value is already stored in mongodb then, that value is not storing again(or I say duplicate values are not getting stored in mongodb)

Can someone help me out.I was using saveAll() of mongodb.

repo.saveAll(list1);

If any list which has a column named as 'id' has a value 4. If I'am storing another list with same id i.e 4, then I'am unable to store it.

CodePudding user response:

You can't store duplicates on indexes. An index is usually set in the schema. The id field native to mongoDB is always an index.

If you want to remove that you have to declare it with this:

db.collection.dropIndex("id") 
// Or
db.collection.dropIndex("_id") 

Here the docs

  • Related