ORACLE-BASE - Oracle REST Data Services (ORDS) _ Oracle Database API for MongoDB
ORACLE-BASE - Oracle REST Data Services (ORDS) _ Oracle Database API for MongoDB
8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23ai | Misc | PL/SQL |
SQL | RAC | WebLogic | Linux
Home » Articles » Misc » Here
ORDS Setup
Database Setup
Create some JSON Collections (23ai optional)
MongoDB Compass
MongoDB Shell (mongosh)
Related articles.
Oracle REST Data Services (ORDS) : Standalone Mode (ORDS Version 22.1 Onward)
JSON Collections in Oracle Database 23ai
Oracle REST Data Services (ORDS) : Simple Oracle Document Access (SODA) for REST
Simple Oracle Document Access (SODA) for PL/SQL in Oracle Database 18c
ORDS Setup
We are going to assume you have an ORDS installation at version 22.3 or higher, running in
standalone mode. If not, you can find out how to install ORDS here.
Oracle REST Data Services (ORDS) : Standalone Mode (ORDS Version 22.1 Onward)
cd /u01/ords/bin
ords config set mongo.enabled true
During the startup we see a log message showing the MongoDB API connection URI.
2024-10-04T13:21:37.499Z INFO The Oracle API for MongoDB connection string is:
mongodb://[{user}:{password}@]localhost:27017/{user}?authMechanism=PLAIN&authSou
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 1/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
Substituting our credentials we get the following. Remember to adjust the hostname if ORDS is
running on a different server.
mongodb://sodauser:sodauserpwd1@localhost:27017/sodauser?authMechanism=PLAIN&authSource=$
mongodb://sodauser:sodauserpwd1@localhost:27017/sodauser?authMechanism=PLAIN&authSource=$
Database Setup
We create a test user to hold our MongoDB collections. It needs to be able to connect and create
tables for the basic functionality. We are going to build some additional objects, so we grant it
DB_DEVELOPER_ROLE. It's important to grant the SODA_APP role.
conn sodauser/sodauserpwd1@//localhost:1521/freepdb1
begin
ords.enable_schema(
p_enabled => TRUE,
p_schema => 'SODAUSER',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'sodauser',
p_auto_rest_auth => FALSE
);
commit;
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 2/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
end;
/
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 3/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
We create a JSON-relational duality view based on the EMP and DEPT tables.
We create a JSON collection view based on the EMP and DEPT tables.
MongoDB Compass
Download MongoDB Compass from here.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 4/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 5/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
Put the amended URI into the dialog and click the "Save" button.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 6/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
Expand the connection, which connects via the MongoDB API. Notice the JSON-relational duality
view and JSON collection table are visible as collections under the "sodauser" database.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 7/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
We click on the "DEPARTMENTS_DV" collection and we can expand the nodes to see the data.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 8/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 9/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 10/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 11/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 12/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 13/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
To add a new collection, hover over the "sodauser" tree node and click the "+" button that
appears. That opens the "Create Collection" screen.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 14/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
The new collection is now visible in the list. We could add some data to it, like we did previously.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 15/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
If we check the database we can see a table has been created to hold the collection data.
select table_name
from user_tables
order by 1;
TABLE_NAME
--------------------------------------------------------------------------------
DEPT
EMP
FRUIT_JCT
my_collection
SQL>
COLLECTION_NAME COLLECTION_T
-------------------- ------------
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 16/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
SQL>
mkdir /u01/mongosh
cd /u01/mongosh
tar -xvzf /tmp/mongosh-2.3.1-linux-x64.tgz
cd /u01/mongosh/mongosh-2.3.1-linux-x64/bin
We start mongosh and connect to "sodauser" using the connection URI we discussed earlier.
$ ./mongosh 'mongodb://sodauser:sodauserpwd1@localhost:27017/sodauser?authMechanism=PLAIN
Current Mongosh Log ID: 67015d95c5d2ec5988964032
Connecting to: mongodb://@localhost:27017/sodauser?authMechanism=PLAIN&authSourc
Using MongoDB: 4.2.14
Using Mongosh: 2.3.1
To help improve our products, anonymous usage data is collected and sent to MongoDB perio
You can opt-out by running the disableTelemetry() command.
sodauser>
The following commands are all run from this command prompt.
my_collection
sodauser>
sodauser> db.FRUIT_JCT.find();
[
{
_id: ObjectId('67002ac50000012114a94e3b'),
fruit: 'apple',
quantity: 10
},
{
_id: ObjectId('67002ac50000012114a94e3e'),
fruit: 'oranges',
quantity: 5
},
{
_id: ObjectId('6700344f74bd1bab031b545a'),
fruit: 'pineapple',
quantity: 20
}
]
sodauser>
sodauser> db.createCollection('my_collection2');
{ ok: 1 }
sodauser>
We insert data into the collection. Notice the collection name is references in the command.
sodauser> db.my_collection2.insertOne({"fruit":"apple","quantity":10});
{
acknowledged: true,
insertedId: ObjectId('670160d5c5d2ec5988964033')
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 18/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
}
sodauser>
sodauser> db.my_collection2.insertOne({"fruit":"banana","quantity":5});
{
acknowledged: true,
insertedId: ObjectId('67016100c5d2ec5988964034')
}
sodauser>
We display a specific document. First by searching for a specific element value, and second by
searching for a specific "_id" value.
sodauser> db.my_collection2.find({"fruit":"apple"});
[
{
_id: ObjectId('670160d5c5d2ec5988964033'),
fruit: 'apple',
quantity: 10
}
]
sodauser>
We update the document, setting a new quantity, then display the updated document.
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 19/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
sodauser> db.my_collection2.find({"fruit":"apple"});
[
{
_id: ObjectId('670160d5c5d2ec5988964033'),
fruit: 'apple',
quantity: 20
}
]
sodauser>
We drop the collection called "my_collection2", and check it is removed from the collection list.
sodauser> db.my_collection2.drop();
true
sodauser>
We exit mongosh.
sodauser> exit
$
Contact Us
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 20/21
02/12/2024 17:12 ORACLE-BASE - Oracle REST Data Services (ORDS) : Oracle Database API for MongoDB
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-oracle-database-api-for-mongodb 21/21