Here is a simple example of a data pipeline that transfers data from an Oracle database to a MongoDB database using Python:
# Import necessary libraries
import cx_Oracle
from pymongo import MongoClient
# Connect to the Oracle database
orcl = cx_Oracle.connect(
user="oracle_user",
password="oracle_password",
dsn="oracle_host:oracle_port/oracle_service"
)
# Connect to the MongoDB database
mongodb = MongoClient("mongodb_host:mongodb_port")
db = mongodb["mongodb_database"]
# Create a cursor to perform operations on the Oracle database
orclcursor = orcl.cursor()
# Execute an Oracle query to retrieve the data
orclcursor.execute("SELECT * FROM oracle_table")
# Fetch the result of the Oracle query
oracle_data = orclcursor.fetchall()
# Loop through the result and insert each row into the MongoDB collection
for row in oracle_data:
db.mongodb_collection.insert_one({
"column1": row[0],
"column2": row[1],
"column3": row[2]
})
# Close the cursor and database
orclcursor.close()
orcl.close()
This script uses the cx_Oracle
library to connect to the Oracle database, and the pymongo
library to connect to the MongoDB database. It then retrieves the data from the Oracle table and inserts it into the MongoDB collection. You can modify this script as needed for your specific databases and use case.