Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Migrate a MongoDB Database Running on MongoDB Atlas or On-Premises to Oracle Autonomous JSON Database
Introduction
MongoDB is one of the popular open-source databases used to create and store data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time.
Oracle, which is one of world famous leading relational, multi-model database called as Converged Database, has good capability of handling JSON. Oracle introduced support for JSON from v12c, stored JSON data as varchar2 or Large Object (LOB) (Character Large Object (CLOB)/Binary Large Object (BLOB)).
Challenges with MongoDB:
-
MongoDB is fast to get started, but it lacks key features for enterprise deployments.
-
Limited transaction support leads to data consistency challenges.
-
Difficult and inefficient analytic queries (and no parallel query).
-
Immature security features.
-
American National Standards Institute Structured Query Language (ANSI SQL) functionality.
Advantage of using JSON Data Type in Oracle:
-
From Oracle version 21c, JSON stored in native format, so users can query JSON documents using standard SQL which enabled to build application with the flexibility of a schema-less design model with all the power of Oracle Database like replication, partitioning, indexing with all the functionalities that the Oracle Database is capable of.
-
JSON can be manipulated through SQL query.
-
Stored as OSON (a optimized native binary representation of JSON).
Note: Make sure connectivity is established between Oracle Cloud Infrastructure (OCI) GoldenGate Big Data deployment, source and target databases.
Objectives
- Set up MongoDB and Oracle Autonomous JSON Database using OCI GoldenGate Big Data deployment.
Prerequisites
-
Provision the following resources:
-
OCI environment like (compartment, virtual cloud network (VCN), subnet and so on).
-
Oracle Autonomous JSON Database.
-
OCI Compute VM for MongoDB replica set.
-
OCI GoldenGate Big Data deployment.
-
Task 1: Install MongoDB Binary and Start MongoDB Services
-
Create three OCI Compute instances for replication setup and attach block volume for data directory.
-
Update
yum
repos to download MongoDB binary using the following command.vi /etc/yum.repos.d/mongodb-enterprise-8.0.repo [mongodb-enterprise-8.0] name=MongoDB Enterprise Repository baseurl=https://repo.mongodb.com/yum/redhat/8/mongodb-enterprise/8.0/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-8.0.asc sudo yum install -y mongodb-enterprise
-
Create data directory and grant required permission using the following command.
cd /data ls chmod 755 mongo cd chmod 755 -R /data/mongo chown mongod:mongod -R /data/mongo chmod 400 /etc/mongod.Keyfile chown mongod:mongod -R /etc/mongod.Keyfile
Note: Keyfile is needed for secure authentication. For testing purpose, keyfile can be generated using the
open-ssl
command. -
Create config file using the following command.
cat /etc/mongod.conf
-
Disable
selinux
and startmongod
services using the following commands.setenforce 0 getenforce systemctl start mongod systemctl status mongod
-
Perform the same operations on remaining two nodes which will be acting as the secondary node.
Task 2: Create MongoDB Replica Set
-
Connect to first node and connect to admin database.
-
Run the following commands to initiate replication and create first admin user. This replication user will be used for replication configuration and management.
mongosh use admin
rs.initiate() db.createUser({ ... user: "admin", ... pwd: "password", ... roles: [ ... { role: "root", db: "admin" } ... ] ... })
db.auth("admin","password") rs.conf()
-
Add remaining two nodes using the following commands. Those will be added as secondary nodes.
rs.add("10.0.1.163;27017")
rs.add("10.0.1.51:27017")
-
Check configuration and status of replica set using the following commands.
db.auth("admin","password") rs.conf()
rs.status()
rs.printReplicationInfo()
Task 3: Load Data into MongoDB Replica Set
-
Restore the dump into MongoDB replica set using the
mongorestore
command.mongorestore --username admin --password password dump/
Note: The above dump was obtained from another MongoDB replica set using
mongodump
command for all databases running under that replica set. -
Run the following command to check if all databases and its respective collections have been restored into MongoDB replica set.
mongosh use admin db.auth("admin","password") show dbs
Task 4: Configure Oracle Autonomous JSON Database in OCI
-
Log in to the OCI Console, navigate to Oracle Database, Autonomous Database and enter the following information as shown in the images to create autonomous database.
Note: For MongoDB compatibility, network access needs to be set to either secure access from allowed IPs and VCNs only or private endpoint access only.
-
Click Edit tool configuration, enable MongoDB API and copy the URL.
Note: You need to change the username and password in above connection string.
Task 5: Create Database Client Machine to Access Oracle Autonomous JSON Database and Install Required MongoDB Tools
-
Download wallet file and configure connectivity for Oracle Autonomous JSON Database using the following commands.
cat tnsnames.Oracle
cat sqlnet.Ora
-
Download MongoDB tools for connectivity using the following commands.
wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel70-x86_64-100.5.2.tgz
tar -xvf mongodb-database-toosl-rhel70-x86_64-100.5.2.tgz
wget https://downloads.mongodb.com/compass/mongosh-1.3.1-linux-x64.tgz
tar -xvf mongosh-1.3.1-linux-x64.tgz
-
Set Path and URI (Oracle Autonomous Transaction Processing (ATP) endpoint) as environment variable using the following commands.
cd export PATH=/home/oracle/mongosh-1.3.1-linux-x64/bin/:$PATH export PATH=$PATH:/home/oracle/mongodb-database-tools-rhel70-x86_64-100.5.2/bin echo $path
-
Check if you are able to connect to Oracle Autonomous JSON Database using the following command.
export URI='mongodb://admin:xxxx@xxxxxx-ADBJ.adb.us-ashburn-1.oraclecloudapps.com:27017/admin?authMechanism=PLAIN&authSource=$external&ssl=true&retryWrites=false&loadBalanced=true' mongosh $URI
Task 6: Upload Dump to OCI Object Storage Bucket and Import into ATP
-
Take dump of a collection using the
mongoexport
command.mongoexport --host=mrep1 --port 27017 --username=admin --authicationDatabase=admin --collection=data --db=sample_weatherdata --out=wheather_data.Json
-
Click Upload to upload dump of a single collection of database which was taken using the
mongoexport
command on MongoDB replica set. -
Click View Object Details to get object endpoint detail.
-
Run the
curl
command to read the data from that object and themongoimport
command to ATP using endpoint.curl -X GET https://objectstorage.us-ashburn-1.oraclecloud.com/p/ujXv8Pmhxt9EyLlA9ogm_X524pDRGEymJwbDVyUExAACra1VpAql32U0XaRnaxLt/n/orasenatdoracledigital01/b/jsonbucket/o/wheather_data.json | mongoimport --collection data --uri $URI
-
Check if collection has been imported into the ATP database.
-
Crosscheck if the number of documents is same as the source.
Test is Successful. Now, we are good to move all data running under multiple databases in source MongoDB replica set to target Oracle Autonomous JSON Database and deploy OCI GoldenGate services for near zero downtime migration.
-
For data movement you can use the
mongodump
command to copy data from source to target database as a one time load.export URI="mongodb://mrep1:27017 --username admin --authenticationDatabase admin" mongodump --uri=$URI
-
Copy this dump to the target system from where you can run the
mongorestore
command (already explained in Task 3 to load into target Oracle Autonomous JSON Database).Note: Make sure to create the same schema name in Oracle Autonomous JSON Database for the database collections you want to migrate.
create user sample_airbnb identified by <password>; grant connect, resource to sample_airbnb; grant unlimited tablespace to sample_airbnb; BEGIN ORDS_ADMIN.ENABLE_SCHEMA(p_schema => 'SAMPLE_AIRBNB'); commit; END; /
Task 7: Deploy OCI GoldenGate
-
Go to the OCI Console, navigate to Oracle Database, GoldenGate, Deployments and click Create deployment.
For MongoDB to Oracle Autonomous JSON Database, we need to select Technology as Big Data and Deployment Type as Data Replication.
-
Create secret in advance from the OCI Console for admin user log in and management.
Task 8: Create Connection for both MongoDB and Oracle Autonomous JSON Database
-
Go to the OCI Console, navigate to Oracle Database, GoldenGate, Connections and click Create connection.
-
Enter the following information as shown in the image to create source database connection.
-
Repeat step 1 and enter the following information as shown in the image to create target database connection.
Task 9: Assign and Test Connection to OCI GoldenGate Deployment
-
Go to the OCI Console, navigate to Oracle Database, GoldenGate, Connections and click the connection created in Task 8.
-
Click Assigned deployments and Assign deployment.
-
Select the deployment and click Assign deployment.
-
Click the three dots and Test connection to make sure it is successful.
Task 10: Create Extract and Replicat Processes
-
Go to the OCI Console, navigate to Oracle Database, GoldenGate, Deployments and click the deployment created in Task 7.
Click Launch Console and this will open the OCI GoldenGate configuration console.
-
Enter the Username and Password which was created during deployment.
Once you are logged in to the console page, you can see all required options for Extract and Replicat configuration. You can create extract and replicat services as shown in the later steps.
-
Configure extract process.
Select Connection Alias which has been created for the source MongoDB database.
In Parameter File,
sample_airbnb
is a database in MongoDB and*
represents all the collections in that database. -
Configure replicat process.
-
Select Classic Replicat as Replicat Type.
-
Enter the following required information.
You need to select the same trail filename, which has been named in extract process creation. Select Target as Oracle Autonomous JSON Database and enter Connection Alias which has been created in Task 8.
Replicat process will replicat all the transactions from
sample_airbnb
database in MongoDB tosample_airbnb
schemas in Oracle Autonomous JSON Database.
Note: You need to change the source and target database name and schema name respectively in the configuration.
-
-
Once you are done with extract and replicat process configuration, start process accordingly.
Note: Oracle Autonomous JSON Database should be configured with a private endpoint. If certificate is not used, you can change authentication as without mutual TLS (mTLS).
In case the correct certification is not available, you may get the following error in the replication logfile:
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Task 11: Start Extract and Replicate Processes and Validate
Click Administrative Service to check both processes status and its respective reports and log files for any issue.
-
Extract process status:
-
Replicat process status:
Task 12: Test Data Synchronization
-
In source and target, check document count in the collection detail before inserting some data using the following commands.
-
Source database:
show dbs use sample_airbnb show collections db.emp.countDocuments()
-
Target database:
show dbs use Sample_airbnb show collections db.emp.countDocuments()
-
-
Check data on source and target database using the following commands.
-
Source database:
db.emp.find({"name":"joe"}) db.emp.find({"name":"John"})
-
Target database:
db.emp.find({"name":"joe"}) db.emp.find({"name":"John"})
-
-
Insert data on source and check if it has been replicated to target using the following commands.
-
Source database:
dm.emp.insertOne( { "name":"John","job":"Data Analyst","Salary":7000}) db.emp.countDocuments() db.emp.find({"name":"John"})
-
Target database:
show DBs show collections db.emp.find({"name":"John"})
-
Task 13: Connect To MongoDB Atlas
Connecting to MongoDB Atlas is different than connecting to an On-premises MongoDB database.
-
The following MongoDB Atlas default connection string is not supported.
mongodb+srv://<db_username>:<db_password>@cluster0.xxxxx.mongodb.net/
-
For successful connection, we need to use the following connection string.
mongodb://cluster0-shard-00-00.xxxx.mongodb.net:27017,cluster0-shard-00-01.xxxx.mongodb.net:27017,cluster0-shard-00-02.xxxx.mongodb.net:27017/?ssl=true&replicaSet=xxxx&authSource=admin&retryWrites=true&w=majority&appName=Cluster0
Note: Make sure you create a NAT gateway and attach with private subnet which is being used by OCI GoldenGate deployment as well if connection needs to be established in a public network.
Common Errors Due to Connectivity Issues
Connectivity issue to target Oracle Autonomous JSON Database can lead to miscellaneous errors while starting the replicate process:
-
Error 1:
ERROR OGG-01091 Unable to open file "/u02/Deployment/var/lib/data/a1000000000" (error 2, No such file or directory).
-
Error 2:
ERROR OGG-15051 Java or JNI exception: java.lang.NoClassDefFoundError: oracle/goldengate/datasource/UserExitMain. oracle.goldengate.util.GGException: Error detected handling transaction commit event. Exception in thread "main" oracle.goldengate.util.GGException: Error detected handling transaction commit event. at oracle.goldengate.datasource.UserExitDataSource.commitTransaction(UserExitDataSource.java:261 at oracle.goldengate.datasource.UserExitDataSource.commitTx(UserExitDataSource.java:2180) Caused by: java.net.SocketTimeoutException: Connect timed out
-
Error 3: In case of integrated replicate, you might encounter the following error:
OGG-01091 Oracle GoldenGate Delivery, RSNOW.prm: Unable to open file "/u02/Deployment/etc/conf/ogg/<replicat name>001.properties" (error 2, No such file ordirectory). In that case, you need to set below parameter in property file of Replicate parameter. TARGETDB LIBFILE libggjava.so SET property=/u02/Deployment/etc/conf/ogg/<replicatname>.properties
-
Error 4: Connection in MongoDB Atlas using default connection string is not supported using OCI GoldenGate Big Data deployment. You will get an error as shown in the following image.
Related Links
Acknowledgments
- Author - Ashish Srivastava (Principal Cloud Architect, Oracle North America Cloud Services - NACIE)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Migrate a MongoDB Database Running on MongoDB Atlas or On-Premises to Oracle Autonomous JSON Database
G26103-01
February 2025
Copyright ©2025, Oracle and/or its affiliates.