Using spring-data-mongodb to insert data in batches, how do you know that some of the data was not successfully inserted?

  mongodb, question

I want to use the spring-data-mongodb interface to perform batch insertion of 100 pieces of data at a time. The interface description is as follows:

 * reference:
 * reference:
 * Insert a list of objects into the specified collection in a single batch write to the database.
 * @param batchToSave the list of objects to save.
 * @param collectionName name of the collection to store the object in
 void insert(Collection<?   extends Object> batchToSave, String collectionName);

However, there is a problem here: when there are duplicate unique indexes, the insertion operation will be “partially successful”-some documents are successfully inserted and some are not.I would like to know when the insertion failed, which failed and which succeeded.. However, the above interface does not return a value. Has anyone encountered this problem?

Meeting the same problem,spring-data-mongodbThe version is1.8.2.RELEASE.

When inserting data that already has a unique index id, there is no return value, no exception, and the original data will not be affected.

My later solution is to query before inserting. If the existing data is found according to id, the insertion will not be performed and the data will be saved to the returned result.

public Person getObject(String id) {
 return mongoTemplate.findOne( new Query( Criteria.where( "id" ).is( id ) ),Person.class );

If you have a better solution, welcome to exchange.