10107 NotWritablePrimary: not master / not writable primary
MongoDBWhat 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().
More from this engine
- 67 CannotCreateIndexCannot create index
- 27 IndexNotFoundIndex not found
- 79 UnknownReplWriteConcernUnknown replica set write concern
- 91 ShutdownInProgressThe server is in the process of shutting down
- 189 PrimarySteppedDownPrimary stepped down while operation was in progress
- 24 LockTimeoutOperation exceeded time limit waiting for a lock
- 7 HostNotFoundCould not find host