Migrate from MongoDB JSON file to an Oracle NoSQL Database Cloud Service
This example shows how to use the Oracle NoSQL Database Migrator to copy Mongo-DB Formatted Data to the Oracle NoSQL Database (NDCS).
Use Case
After evaluating multiple options, an organization finalizes Oracle NoSQL Database as its NoSQL Database platform. As its NoSQL tables and data are in MongoDB, they are looking for a way to migrate those tables and data to Oracle NDCS.
You can copy a file or directory containing the MongoDB exported JSON data for migration by specifying the file or directory in the source configuration template.
{"_id":0,"name":"Aimee Zank","scores":[{"score":1.463179736705023,"type":"exam"},{"score":11.78273309957772,"type":"quiz"},{"score":35.8740349954354,"type":"homework"}]}
{"_id":1,"name":"Aurelia Menendez","scores":[{"score":60.06045071030959,"type":"exam"},{"score":52.79790691903873,"type":"quiz"},{"score":71.76133439165544,"type":"homework"}]}
{"_id":2,"name":"Corliss Zuk","scores":[{"score":67.03077096065002,"type":"exam"},{"score":6.301851677835235,"type":"quiz"},{"score":66.28344683278382,"type":"homework"}]}
{"_id":3,"name":"Bao Ziglar","scores":[{"score":71.64343899778332,"type":"exam"},{"score":24.80221293650313,"type":"quiz"},{"score":42.26147058804812,"type":"homework"}]}
{"_id":4,"name":"Zachary Langlais","scores":[{"score":78.68385091304332,"type":"exam"},{"score":90.2963101368042,"type":"quiz"},{"score":34.41620148042529,"type":"homework"}]}
MongoDB supports two types of extensions to the JSON format of files, Canonical mode and Relaxed mode. You can supply the MongoDB-formatted JSON file that is generated using the mongoexport tool in either Canonical or Relaxed mode. Both the modes are supported by the NoSQL Database Migrator for migration.
For more information on the MongoDB Extended JSON (v2) file, See mongoexport_formats.
For more information on the generation of MongoDB-formatted JSON file, See mongoexport.
Example
For the demonstration, let us look at how to migrate a MongoDB-formatted JSON file to NDCS. We will use a manually created configuration file for this example.- Identify the source and sink for the migration.
- Source: MongoDB-Formatted JSON File
- Sink: Oracle NoSQL Database
- Extract the data from Mongo DB using the mongoexport utility. See mongoexport for more information.
- Create a NoSQL table in the sink with a table
schema that matches the data in the Mongo-DB-formatted JSON
file. As an alternative, you can instruct the NoSQL Database Migratorto create a table with the
default schema structure by setting the
defaultSchema
attribute to true.Note:
For a MongoDB-Formatted JSON source, the default schema for the table will be as:CREATE TABLE IF NOT EXISTS <tablename>(ID STRING, DOCUMENT JSON,PRIMARY KEY(SHARD(ID))
Where:tablename
= value of the table config.ID
=_id
value from the mongoDB exported JSON source file.DOCUMENT
= The entire contents of the mongoDB exported JSON source file is aggregated into theDOCUMENT
column excluding the_id
field.
- Identify your OCI cloud credentials and capture them
in the OCI config file. Save the config file in
/home/.oci/config
.See Acquiring Credentials in Using Oracle NoSQL Database Cloud Service.[DEFAULT] tenancy=ocid1.tenancy.oc1.... user=ocid1.user.oc1.... fingerprint= 43:d1:.... key_file=</fully/qualified/path/to/the/private/key/> pass_phrase=<passphrase>
- Identify the region endpoint and compartment name
for your Oracle NoSQL Database.
- endpoint:
us-phoenix-1
- compartment:
developers
- endpoint:
To migrate the MongoDB-formatted JSON data to the Oracle NoSQL Database:
To validate the migration, you
can login to your NDCS console and verify that
myTable
is created with the source
data.