In this article, we have covered a possible approach to integrate Boomi Atomsphere with MongoDB using RESTHeart service. RESTHeart provides a REST interface to interact with MongoDB using JSON over HTTP.
MongoDB is one of the most prominent NoSQL databases. It works on the concept of documents and collections. A document is a set of key-value pairs. MongoDB's documents are encoded in a JSON-like format, called BSON (binary JSON). A collection is a group of MongoDB documents. More details can be found on MongoDB’s website.
While there are number of interfaces and tools available for integrating with MongoDB, we will be using the RESTHeart API because it provides a lightweight REST interface, easy setup, and high performance. The RESTHeart API enables CRUD operations on MongoDB’s document and collections. With AtomSphere’s HTTP Connector it’s easy to model the CRUD methods provided by the API.
Installation and Prerequisites
This example requires following setup related activities:
- A local Atom
- Local deployment of MongoDB v3.0 or greater
- RESTHeart v1.0.3 or greater (Setup - https://softinstigate.atlassian.net/wiki/display/RH/Installation+and+Setup)
- The latest and stable release of RESTHeart API requires Java 8
- RESTHeart libraries have been tested with MongoDB version 3.0, 2.6 and 2.x4. For release based dependencies, please see efer - https://github.com/SoftInstigate/RESTHeart/releases
- Start the RESTHeart server and ensure that it connects to MongoDB successfully:
RESTHeart API Tutorial and API Reference
For this POC, I already created a database (dev) and a collection (employees) in MongoDB which would be used to create and query documents from Boomi process
Scenario 1 – Insert/Update an Employee record in Employees collection using POST
creates or updates a document in the collection <collname> of the db <dbname>
- POST has upsert semantic: if the document exists it will be updated, otherwise it will be created.
- The document id can be specified with the optional property _id; otherwise an _id will be created
- Optimistic concurrency control via ETag (entity tag) is required.
For updates, it’s mandatory to provide ETag (https://softinstigate.atlassian.net/wiki/display/RH/ETag) in a HTTP header If-Match. If not passed, server returns HTTP 409 with ETag in the header for the conflicting document.
JSON Profile for the Object:
Branch 1 attempts to insert a document. If there is a conflict (HTTP 409 response), then it saves ETag and use it in Branch 2 for Update
Scenario 2 – Querying document based on a filter
This returns the HAL representation of the collection <collname> of db <dbname> with its documents as embedded resources
- Paging supported.
- Sorting supported.
- Filtering supported.
- ETag based caching supported (entity tag).
- Eager db cursors preallocation supported. Dramatically improves read performances on big collections.
Note – Before Sending to connector filter in the URI should be encoded (http://www.w3schools.com/jsref/jsref_encodeURI.asp)