Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2426

Check if indexes for GridFS exist prior to creating them

    • 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
      
      

            Assignee:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: