-
Type: Task
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.4.2
-
Component/s: Public API
-
None
-
Environment:PROD and QA
Hi there! We just upgraded from mongodb 2.6.6 and mongoid 4.x to mongodb 3.4.3 and mongoid 5.2. We are using the ruby 2.4.2 mongo driver. We have some code to copy collections from one server to another. We used to use the Moped classes to do this, but the rename method is not available on the Mongo::Collection object. I have listed the OLD Code snippet below AND the* NEW Code* snippet. Looking for some direction on rewriting the items in red below in the NEW Code snippet using the mongo driver. Thanks! -Steve
OLD Code:
def copy_footnotes_from_prod
session_to = Moped::Session.connect(Settings.footnotes_copy["#
_mongo_uri"])
prod_master = nil
prod_session = Moped::Session.connect(Settings.footnotes_copy.prod_mongo_uri)
response = prod_session.command(ismaster: 1)
prod_master = response[:primary] if response[:primary].present?
prod_session.disconnect
if prod_master
session_to[:footnotes_backup].drop
session_to[:footnotes].rename("footnotes_backup")
return_hash1 = session_to.command(
)
session_to[:footnotes_backup].drop
session_to.disconnect
Rails.logger.info "1> #
message = "Successfully copied footnotes From Prod to DEV"]}"
else
message = "No Master Found"
end
redirect_to admin_path, notice: message
* end*
*NEW CODE:
def copy_footnotes_from_prod*
session_to = Mongo::Client.new(Settings.footnotes_copy["dev_mongo_uri"],
:connect => :replica_set, :read => { :mode => :primary},
:auth_mech => :scram,
:auth_source => :admin,
:user => "ourID",
:password => "DONOTSHOW")
prod_session = Mongo::Client.new(Settings.footnotes_copy["prod_mongo_uri"],
:connect => :replica_set, :read => { :mode => :primary},
:auth_mech => :scram,
:auth_source => :admin,
:user => "ourID",
:password => "DONOTSHOW")
if prod_session
ft = session_to[:footnotes_backup]
ft.drop
cc = session_to[:footnotes]
cc.renameCollection("footnotes_backup")
return_hash1 = session_to.command({cloneCollection: "fund.footnotes", from: prod_session})
dd = session_to[:footnotes_backup]
dd.drop
session_to.disconnect
prod_session.disconnect
Rails.logger.info "1> #{return_hash1}
"
message = "Successfully copied footnotes From Prod to DEV"]}"
else
message = "No Master Found"
end
redirect_to admin_path, notice: message
- end*