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