Export data from Oracle to MongoDB in Python

Introduction

I had to export some data from an Oracle database to a MongoDB. For this reason I created a python function called export_data_from_oracle_to_mongodb that can be found in my Github.

To make the function more generic, I've there's an optional parameter called transform,where a function can be specified to make some transformations (like combining columns, casts, etc...) without having to modify the function.

Linux environment variables

Before running the script, the following environtment variables must be set (to the correct folder, here it's just an example). If it's executed in Jupyter Notebook, run the exports before the jupyter notebook command:

Execute the exportation

# Configuration parametersip='oracle_ip'port=PORT_NUMBERSID='ORACLE_SID'ora_user='username'ora_password='password'my_mongodb='mongodb://localhost:27017/'my_mongodb_db='mydb'my_mongodb_col='my_collection'# The SQL query MUST NOT have semi-colon (";") at the end!consulta_sql=u"""SELECT * FROM DUAL"""export_data_from_oracle_to_mongodb(oracle_server=ip,oracle_port=port,oracle_sid=SID,oracle_user=ora_user,oracle_password=ora_password,mongodb_connection_string=my_mongodb,mongodb_database=my_mongodb_db,mongodb_collection=my_mongodb_col,create_mongodb_collection_if_not_exist=True,sql_query=consulta_sql,transform=add_coord)