-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Fully Compatible
In FSBucket class we have the following implementation of ensuring that indexes exist:
def ensure_indexes! if files_collection.find({}, limit: 1, projection: { _id: 1 }).first.nil? chunks_collection.indexes.create_one(FSBucket::CHUNKS_INDEX, :unique => true) files_collection.indexes.create_one(FSBucket::FILES_INDEX) end end
Per divjot.arora this violates https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst#before-write-operations, specifically:
> Drivers MUST check whether the indexes already exist before attempting to create them. This supports the scenario where an application is running with read-only authorizations.
Note that the suggested sequence of operations is as follows:
------------
When uploading a file to a GridFS bucket, can drivers confirm that they do operations in the following order? This is assuming that the upload is the first write to the bucket: findOne() on the files coll to check if it's empty listIndexes on fs.files createIndexes on fs.files to create the { filename : 1, uploadDate : 1 } index listIndexes on fs.chunks createIndexes on fs.chunks to create the { files_id : 1, n : 1 } index one or more insert() calls on the chunks coll to insert chunks insertOne() on the files coll to create the final files document