I have a spring-boot
application which has the service to process and save a list of around 100 objects in a go.
Everythings seems fine till the processing state but calling save
method of MongoRepository
throws following exception:
com.mongodb.DuplicateKeyException: Write failed with error code 11000 and error message 'E11000 duplicate key error collection: uhtableau_db.ticket index: _id_ dup key: { : 0 }'
I retried after cleaning the db as well but same error. Unable to understand what am I doing incorrectly.
Here is the document object:
@Document
public class Ticket {
public Ticket(){
}
@Id
private long id;
private long ticket_id; // this is the field in the json which i am processing
private String topic;
private List<String> tag;
private String type;
private long brand;
private long group;
private String priority;
private String status;
private String created_at;
private String channel;
}
I create a list of this Ticket
document after processing some json data as input. I need to save this list in mongo.
Here is what am doing:
@Autowired
TicketRepository ticketRepository;
@GetMapping("/tickets")
public void saveTicketData(){
List<Ticket> tickets = ZendeskClient.parseJsonForTicketList(ticketJson);
ticketRepository.save(tickets);
}
And TicketRepository
:
public interface TicketRepository extends MongoRepository<Ticket, Long> {
}