RUBY-351 Build GridFS indexes when a primary is present.
This commit is contained in:
parent
24b9653366
commit
93f228aaf1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue