DBAtlas · Database operations atlas

10107 NotWritablePrimary: not master / not writable primary

MongoDB

What does it mean?

A write (or another operation that requires the primary) was sent to a replica set member that is not currently the primary. Only the primary accepts writes, so the operation was rejected.

Why does it happen?

The application is writing to a secondary; during a failover (election) the old primary became a secondary and the client is still connected to it; or the driver's read/write preference and topology information is stale. A missing replicaSet parameter in the connection string is the typical cause.

How to fix it

Configure the driver with all replica set members and the replica set name (replicaSet=... and all hosts in the connection string) so the driver discovers the primary automatically and re-routes on failover. Use the default read/write preference, which routes writes to the primary. Since this is a transient error, enable retryable writes in the application. Verify which member is PRIMARY with rs.status().

Open in DBAtlas →

More from this engine