RUBY-351 Build GridFS indexes when a primary is present.

This commit is contained in:
Kyle Banker 2011-11-15 15:44:31 -05:00
parent 24b9653366
commit 93f228aaf1
2 changed files with 8 additions and 4 deletions

View File

@ -38,8 +38,10 @@ module Mongo
@chunks = @db["#{fs_name}.chunks"]
@fs_name = fs_name
# Ensure indexes only if not connected to slave.
unless db.connection.slave_ok?
# Create indexes only if we're connected to a primary node.
connection = @db.connection
if (connection.class == Connection && connection.read_primary?) ||
(connection.class == ReplSetConnection && connection.primary)
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
end
end

View File

@ -39,8 +39,10 @@ module Mongo
@default_query_opts = {:sort => [['filename', 1], ['uploadDate', -1]], :limit => 1}
# Ensure indexes only if not connected to slave.
unless db.connection.slave_ok?
# Create indexes only if we're connected to a primary node.
connection = @db.connection
if (connection.class == Connection && connection.read_primary?) ||
(connection.class == ReplSetConnection && connection.primary)
@files.create_index([['filename', 1], ['uploadDate', -1]])
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
end