From Pymongo import mongoclient# connect to the database client=mongoclient (' 192.168.30.252 ', 27017) #获取现有数据库的名称client. Database_names () #将现有的cp到新的client. Admin.command (' Copydb ', fromdb= ' foobar ', todb= ' foobar_new ') #{u ' OK ': 1.0}client.database_names () # [u ' local ', U ' Wocao ', U ' foobar_new ', U ' foobar ', U ' cube_test_2016_04_26 ', U ' mofangdb_2016_06_22 ', u ' Test ', U ' cube_test ' ] #在没有密码的前提下, copy database #client.admin.command on Mongod server (' Copydb ', fromdb= ' remote database name ', todb= ' local target database name ', fromhost= ' The host address of the remote MONGO ') #如果远程mongdb服务存在密码client. Admin.authenticate (' Administrator ', ' pwd ') client.admin.command (' Copydb ') , fromdb= ' Source_db_name ', todb= ' Target_db_name ', fromhost= ' source.example.com ')
Python operation MongoDB four CP database