This is a limitation in the current GridFS spec outlined here.
Instead of using “primary read preference” the find() should use the collection’s read preference (secondary in your case):
Before write operations
Immediately before the first write operation on an instance of a GridFSBucket class is attempted (and not earlier), drivers MUST:
- determine if the files collection is empty using the primary read preference mode.
- and if so, create the indexes described above if they do not already exist
To determine whether the files collection is empty drivers SHOULD execute the equivalent of the following shell command:
db.fs.files.findOne({}, { _id : 1 })
If no document is returned the files collection is empty.