Summary
The GridFS spec does not allow writing to any shard when the primary shard is down as reported here:
https://www.mongodb.com/community/forums/t/issue-with-gridfs-inserts-when-one-of-hte-shard-is-read-only/300340/2
The problem is that the spec requires the driver to "determine if the files collection is empty using the *primary read preference mode*": https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.md#before-write-operations
Instead the spec should use the read preference inherited from the GridFSBucket database. We could also just use primaryPreferred instead of primary.
Motivation
Who is the affected end user?
Users of GridFS + sharding + non-primary read preference.
How does this affect the end user?
When the primary shard goes down, the applications should still be able to write GridFS data to other shards.
How likely is it that this problem or use case will occur?
Edge case.
If the problem does occur, what are the consequences and how severe are they?
It widens an outage.
Is this issue urgent?
Seems high priority.
Is this ticket required by a downstream team?
No.
Is this ticket only for tests?
No.
Acceptance Criteria
Allow non-primary read preferences when writing data to GridFS.