Hi
and I create index with domainId,appId,date field with uqiue index.
I believe the main issue that caused the duplicate key error was caused by the unique index and the code:
val queryDoc = new Document("domainId."1").append("appId","1").append("date","2018-01-01");
If you’re running the same code on two different threads, this queryDoc variable would contain the same value. Since you’re also defining a unique index on the collection, it’s possible that the two threads are finding no document matching the queryDoc and attempted to insert the document at the same time. Essentially this is a race condition in the application, and is described in SERVER-14322.
There are a couple of ways to avoid this error:
Best regards
Kevin