Running MongoDB operations on relational tables

You can run MongoDB operations on HCL OneDB™ relational tables by using the MongoDB API.

About this task

Use the MongoDB database methods to run read and write operations on a relational table as if the table were a JSON collection. The wire listener examines the database and if the accessed entity is a relational table, it converts the basic operations on that table to SQL and converts the returned values into a JSON document. At the first access to an entity, the wire listener caches the name and type of that entity. The first access results in an extra call to the HCL OneDB server, but subsequent operations do not.


From the MongoDB API, enter the relational table name as the collection name in the MongoDB collection method.
For example:


The following examples use the customer table in the stores_demo sample database. All of the tables in the stores_demo database are relational tables, but you can use the same MongoDB collection methods to access and modify the tables, as if they were collections.

Get the customer count
In this example, the number of customers is returned.
> db.customer.count()
Query for a particular customer
In this example, a specific customer record is retrieved.
> db.customer.find({customer_num:101})
{ "customer_num" : 101, "fname" : "Ludwig", "lname" : "Pauli", "company" :
 "All Sports Supplies", "address1" : "213 Erstwild Court", "address2" :
 null, "city" : "Sunnyvale", "state" : "CA", "zipcode" : "94086",
 "phone" : "408-555-8075" }
Update a customer phone number
In this example, the customer phone number is updated.
> db.customer.update({"customer_id":101}, {"$set":{"phone":"408-555-1234"}})