# File lib/mongo/gridfs/grid.rb, line 33 def initialize(db, fs_name=DEFAULT_FS_NAME) raise MongoArgumentError, "db must be a Mongo::DB." unless db.is_a?(Mongo::DB) @db = db @files = @db["#{fs_name}.files"] @chunks = @db["#{fs_name}.chunks"] @fs_name = fs_name # Create indexes only if we're connected to a primary node. connection = @db.connection if (connection.class == MongoClient && connection.read_primary?) || (connection.class == MongoReplicaSetClient && connection.primary) @chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true) end end