Debugging MongoWriteConcernException

i have multiple applications ~5 reading and writing onto the same MongoDB collection in atlas, regular 1min intervals.
and this exception causes my applications to crash all at the same time.
I’m not sure where to begin to prevent this error from crashing my whole setup. any advice is appreciated. driver I’m using is ‘org.mongodb:mongo-java-driver:3.12.7’

Hello @alex_mindustry, welcome to the MongoDB Community forum.

Please post the code which is causing the exception (the stacktrace has the class name and the line numbers of the code causing the exception). Also, tell if your deployment is a replica-set or a sharded cluster.

here is the code… its just the simple insertOne method:

thank you. sorry for the delay in reply

also, i think its replica-set.
according to this screen shot:

Hello @alex_mindustry,

com.mongodb.MongoWriteConcernException - An exception indicating a failure to apply the write concern to the requested write operation.

This is a runtime (or unchecked) exception and it can be thrown by the MongoCollection#insertOne() method (the documentation says so). You can catch this exception in your code - and perform appropriate action as per your need. This way the application will not crash.

Also see, about the WriteConcern. The write concern can be set for the collection, database or the mongo client connection. It can also be specified for a specific operation. Verify if you have set any or the default values are applied. The main options are the “w” and the “wtimeout” - these can affect the inserts and updates on the collection in a replica-set.

At this point itis difficult to conclude what the issue is, but I will try to post more details.