Oracle Database API for MongoDB
Oracle Database API for MongoDB enables the use of MongoDB drivers, frameworks, and tools to develop your JSON document-store applications against the Oracle Database. The Oracle Database API for MongoDB, translates the MongoDB wire protocol into SQL statements that are executed using the ORDS connection pools.
In this article we'll go thru the steps involved in enabling and configuring Oracle Database API for MongoDB in Oracle Database 23ai.
We already have Oracle Database 23ai installed on an OCI VM Compute instance.
Here are the steps -
Install and configure ORDS
Rename the existing ords folder under $ORACLE_HOME.
Create ords directory under $ORACLE_HOME and unzip the ords zip file.
$ cd $ORACLE_HOME
$ mv ords ords.old
$ mkdir ords
$ cd ords
$ unzip ords-24.4.0.345.1601.zip
Run the ords installer.
$ cd $ORACLE_HOME/ords/bin
$ ./ords install
When running the installer, ensure that the PDB is selected and not the CDB. Oracle API for MongoDB is only supported for installations in a non-CDB database or PDB.
Select option 3 to update the ORDS_PUBLIC_USER password
Verify the following is displayed at the end of the installation.
At this point, cancel the installation.
By default, the Oracle API for MongoDB is not enabled. To enable the API, in your configuration, include the following:
$ ./ords config set mongo.enabled true
Start ORDS
$ ./ords serve
Log showing that the Oracle API for MongoDB is enabled:
领英推荐
Create an ORDS-enabled user
Login to the PDB and create an ORDS enabled user
create user foo identified by "<Password>";
grant soda_app, create session, create table, create view, create sequence, create procedure, create job, unlimited tablespace to foo;
connect foo/<Password>
exec ords.enable_schema;
Disable TLS for MongoDB
By default, ORDS uses a self-signed certificate for secure communication. The Mongo API does not allow self-signed certificates, so you cannot directly connect with any Mongo tool or driver to the Mongo API. Let's disable TLS.
$ ./ords config set mongo.tls false
$ ./ords serve
Connect to ORDS using the MongoDB shell
Install MongoDB Shell and use mongosh to connect to the database
$ mongosh 'mongodb://foo:@localhost:27017/foo?authMechanism=PLAIN&authSource=$external&ssl=false&retryWrites=false&loadBalanced=true'
Create a collection and add data to the collection
db.createCollection('emp');
db.emp.insertOne({"name":"Blake","job": "Intern","salary":30000});
db.emp.insertOne({"name":"Smith","job": "Programmer","salary": 60000,"email" : "[email protected]"});
db.emp.insertOne({"name":"Miller","job": "Programmer","salary": 70000});
db.emp.find({"name":"Miller"});
db.emp.updateOne({"name":"Miller"}, {$set: {"email":"[email protected]"}})
Above we created a collection 'emp', added data to the collection, queried the collection and then updated a document in the collection.
The data inserted from the MongoDB client can be accessed from SQL
SQL> select json_serialize(e.data) from emp e;
Refer the documentation on Oracle Rest Data Services - https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/24.4/index.html
Oracle Database API for MongoDB - https://docs.oracle.com/en/database/oracle/mongodb-api/index.html
Database Engineer/Administrator | Data Engineer | Data Analyst | Petroleum Engineer| Energy Mix Analyst | MNSE
1 个月Insightful
Great article!
Distinguished Product Manager - JSON and PL/SQL at Oracle
1 个月Even with 19c!
Cloud Architect - Oracle Database@Azure/GCP/AWS | Tech Evangelist | Pre-Sales | ? Lover
1 个月Josh Spiegel Beda Hammerschmidt Julian Dontcheff