Unlock the power of your application using Oracle Database API for MongoDB

luca bindi
10 min readDec 29, 2022

Today the modern applications use a lot of different types of data, leverage on structured and unstructured data, they use geospatial data or different representation ( like graphs) to speed up analytics queries, they use sometime relational approach and sometime schemaless approch and so on.

Often we have to choose between different products to reach what we really want to get with our application and fit the business needs. Eventually we are forced to put different products together from different vendors to deal with our requirement, and this doesn't always turn out a manageable solution.

Use different vendors’s products means a bit more effort to fill the gap of all different technologies, means to be conscious that for each new version or patch (especially security) we need to dedicate a lot of time to understand the changes and known how to implement them and also we need to test all products combined together to be sure that our application is still working well.

A part of all these stuffs the biggest problem arrives when we need to join the data that are distributed on heterogeneous products and engine, because is not always possible to transform different models of data in a specific model where our application is running on, or we don’t want to duplicate or move the data.

How can we address this requirement? Which products can help us to resolve this complexity?

From my point of view having a single engine for all semantics data mean resolve the problem, save money and be more fast to the new needs that the business will request to you. And please don’t get me wrong, I’m not talking to recreate the monolith at the database level, I’m talking to use the same engine for all types of data and for all Databases… total opposite than recreating a monolith, and as far I know this is possible only with Oracle database today.

The Oracle database is an example of a database can manage all types of data with the same engine, and so it makes easier to bring out the value of your data when you need, you can leverage new type of data when your application or business needs require or they evolve, you are no longer stuck on a single technology at capability at a time.

You can use for instance an Oracle database for spatial or graph data, or have another Oracle database for nosql approch with collection and json documents, or a database with relation data and exploit it for analytics columnar query or at the same time for transactional that perform well with row rappresentation in memory, have a Oracle database onpremise, cloud@customer, on Oracle Cloud infrastructure (OCI) and here have the best of PaaS service (autonomous database) or in a generic hyperscale (like aws or azure), with Oracle database you also can let the data where they reside , for example you can map data (as Avro, ORC, Parquet, Json, Excel , Csv… ) that are on filesystem or on different object storage bucket by external table and realize a modern LakeHouse or a DataMesh solution.

You can use one Oracle database for each type of semantics or use different Oracle databases for each of them, the decision is up to you, because it is not necessary to activate any parameters or licenses, the Oracle database is already ready to manage all this type of data.

And if you decide to use an Oracle database for each model of data, Oracle implemented a multitenat architecture to facilitate the operations, allowing you to manage many Oracle Databases like single one Database (extremely useful when you are not in PaaS service for instance).

Note that Oracle database allows vertical and horizontal scaling, not only using Real application Cluster but also using Sharding configuration (many NoSQL database do it only over their specific single data type, oracle allow sharding over all kind of semantics), and you can also decide to deploy Oracle Database on Kubernetes using Oracle operator.

In conclusion, with Oracle is simple to obtain a complete data platform for any type of data.

But if I have already developed my application on other competitor products such as MongoDB because at the first time my application only needed to store JSON documents, but now if I need to use ML algorithms on the same data to predict my customers' behavior? Or I need to speed up performance for analytics reports and dashboard using a columnar format over json keys? Or if my application needs to use JSON, spatial data and relational data together?

How can I resolve this?Do I need to rewrite all my application’s code and re-test it?

Not at all There is a simpler solution, Oracle rolled out Oracle Database API for MongoDB that let you running your application wrote with Mongodb API on Oracle Database and after that, you will be free to use all potential capabilities that Oracle database can offer about manage all kind of semantics, performance, availability, scaling, security (at the moment the mongodb aggregation pipeline needs to be rewrite).

Indipendent JSON documents performance test

Oracle offers these features not only on Oracle Cloud, but wherever you want and talking about no lock-in products, Oracle also has a great tool called Oracle Golden Gate to feed or synchronize data between different Oracle databases or to other competitors products.

But now let me show you just an example how to use Oracle Database API for MongoDB.

To do this simple test I’ve prepared a Linux machine and installed on it Mongodb. Next I created a json collection

Then I took an example json customer file and load it into mongodb collection by mongoimport tool

I’ve also used Mongo Compass to look through the collection and use QBE for query documents inside the collection

At this point I decide to export my collection by mongoexport tool

I installed Oracle Database just using yum on the same machine(here the rpm software for Oracle Database) .

sudo yum -y install install oracle-database-preinstall-21c

--download Oracle Database rpm software

sudo yum -y localinstall oracle-database-ee-18c-1.0-1.x86_64.rpm

--create a simple database

sudo /etc/init.d/oracledb_ORCLCDB-21c configure

Then I have to install ORDS to enable Oracle Database API for MongoDB, but remember that ORDS is simple tool, but it is also a very powerful tool, it allows you to manage and query all database’s objects by REST.

With ORDS you can also control all database’s lifecycle by REST and use it in CI/CD environment.

Install and configure ORDS is extremely simple, just use yum


sudo yum install ords

--from oracle user

ords --config /home/oracle/ORDSConfig install

##note : I installed it on the pluggable database and not int the container

You can find the complete installation log here

Please as always, refer at the public documentation.

To enable Oracle Database API for MongoDB you have to use, just 2 simple commands…that’s all

ords --config /home/oracle/ORDSConfig config set mongo.enabled true
ords --config /home/oracle/ORDSConfig config set mongo.port 27018

Mongodb is listening on port 27017, while Oracle Database API for MongoDB on port 27018

Let’s create an Oracle database user (Appl1)

SQL> create user appl1 identified by DataBase11;

SQL> GRANT dba TO appl1;
SQL> GRANT SODA_APP TO appl1;

SQL>
BEGIN
ORDS.ENABLE_SCHEMA(p_enabled => TRUE,
p_schema => 'APPL1',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'APPL1',
p_auto_rest_auth => FALSE);
commit;
END;
/


--check
sql appl1/DataBase11@localhost:1521/orclpdb1
--enable ords
exec ords.enable_schema;

Now I want to load the collection exported by mongoexport on my Oracle Database. Obviously Oracle offers several tools and options to load json collection into Oracle Database, but here, I want to show you how you can keep using mongodb tools to do these operations.

Hence, just changing the port and put some little change to the connection string I’m able to use mongoimport against an Oracle database and loading the collection that before was on mongodb

And we can keep using mongo shell too against Oracle database, and we can query the document by QBE using mongo shell, but using Oracle Database.

As said, Oracle provides several tools to work with json / collections and documents, one of these is Sql developer where you can insert, modify query etc etc on JSON documents

A pretty option of SQL Developer is it can show the diagram of json Document, and sometimes it can be very useful

But if you want to continue to use mongo tools like mongo compass, you can do it.

With Mongo compass you can execute against Oracle database the same QBE that you have run on mongodb before.

But now, let’s try Oracle Database API for MongoDB against an application that use mongo-api, to do that I will use a nodejs application found on mogodb site, I have changed some little few things on it , so I suggest to use my version of the application to the test; You can find my version on my GitHub.

On github you will find also the file customers_with_coord.json collection to reproduce exactly the stuffs presented at the beginning of this post.

To have the application on your environment, it’s enough to do these commands

gh repo clone lucbind/Oracle_Mongo_API_Lab

cd Oracle_Mongo_API_Lab

npm init

npm install

The application uses 2 configuration files :

  • database.js

In the file, at the beginning, you can decide which connection you want for run application, over mongodb or over Oracle database, in the example the application will run first on mongo

  • dbFunctions.js

In the file, at the beginning, you can decide the database and collection name, on the example below the application will run on database called Lab_Workshop_Roma and will use a collection called names

To run the mongo-api app execute the following command

node server.js

the app will run on http://localhost:3000/app.html

You can insert data and retrieve information from the collection that will be created on mongodb.

After this, you can kill the nodejs app, and changing the connection towards Oracle Database API for MongoDB to use Oracle Database instead of Mongodb as you can see on the following video.

The application will keep working against Oracle Database, but now you can use all the data with all capabilities that Oracle database offer and take advantage from all types of data managed by Oracle (if you want to see an example, you can read one my previous post about how to exploit Nosql and SQL, blockchain table, spatial etc etc using Oracle Low code Apex and Oracle converged database).

Let me remind you that when you have a json document / collection in Oracle you can access to your data not only by NoSQL approach, but you can use also the SQL approach on the same json collection, and this can turn out very fast and easy especially when you need to execute analysis queries or others.

One more thing, especially if you are a developer, Oracle offers a version of his powerful Oracle Database that enterprises rely on worldwide, completely free with all capabilities: Oracle Database Express Edition (XE) that is the ideal way to get started.

And also you can use the Oracle cloud Autonomous Database and not only it as Always Free cloud services just subscribing here

The post is made for educational purposes and the demo surely could be written better, all checks for all commands haven’t been run; Please use the public documentations.

I hope it’s useful and … have fun

Ciao.
Luca

Disclaimer

The views expressed in this paper are my own and do not necessarily reflect the views of Oracle.

--

--