I am trying to insert the document which is received by input system in mongodb database by using upsert option but it is failing with below error : Anyone help me how to perform the upsert to avoid the duplicate transactions based on field
**Write error: WriteError{code=61, message='Failed to target upsert by query :: could not extract exact shard key', details={}}.**
@ResponseBody
public boolean createTickets(@Valid @RequestBody Document... service) {
MongoDatabase database = this.mongoClient.getDatabase("database");
MongoCollection<Document> collection = database.getCollection("Test");
List<Document> documentList = new ArrayList<>(bookings.length);
for (Document service : bookings) {
documentList.add(Document.parse(booking.toJson()));
}
Document doc= (Document) documentList.iterator().next().get("Price");
String priceResults = (String) doc.get("Ticket");
UpdateOptions options = new UpdateOptions().upsert(true);
UpdateResult updateResult = collection.updateOne(Filters.eq("Price.Ticket", priceResults),
Updates.combine(Updates.set("Price.Ticket", priceResults)), options);
System.out.println("updateResult:- " + updateResult);