-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (22 loc) · 822 Bytes
/
main.py
File metadata and controls
28 lines (22 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pymongo import MongoClient
SOURCE_DB_URL = ""
DESTINATION_DB_URL = ""
# Connect to the source database
source_client = MongoClient(SOURCE_DB_URL)
source_db = source_client['My_DB']
source_collection = source_db['users']
# Connect to the destination database
destination_client = MongoClient(DESTINATION_DB_URL)
destination_db = destination_client['My_DB']
destination_collection = destination_db['users']
# Fetch data from the source collection
data_to_transfer = source_collection.find()
if data_to_transfer:
# Transfer data to the destination collection
destination_collection.insert_many(data_to_transfer)
print("Database users' data transferred.")
else:
print("Database data not found & No data to transfer.")
# Close the database connections
source_client.close()
destination_client.close()