MongoDB Connector for Camunda 8- Part II

In the previous part, we laid the groundwork by creating collections and inserting documents into them. Now, it’s time to extract valuable insights from your data using MongoDB’s robust querying mechanisms.

The MongoDB Connector - Part-II is all about Retrieve functions.

  • Written by

  • Hariharan
    Camunda Expert at Acheron
  • October 9, 2023
  • 9 mins read

Welcome to the second part of our MongoDB blog series! In the previous part, we laid the groundwork by creating collections and inserting documents into them. Now, it's time to extract valuable insights from your data using MongoDB's robust querying mechanisms.

Retrieve Documents :

Let’s create a BPMN diagram and configure the activity to MongoDB database connector. Then, I choose the Operation as “Retrieve Documents”.

Retrieve Documents

  • Since we have not given any values in the FieldNames, Filters, OrderBy, Limit, those operations are omitted and full retrieval is done.

MongoDB Blog-RD1

Retrieval with Projections :

  • As a next step, we are preparing separate charts for each pickup points inorder to proceed with the journey. So, I am conditionally retrieving only the records based on a specific pickup point.
  • This is the sample valid JSON that can be fed into the Filters field.
MongoDB Blog-RD2
  • Let’s model the process and configure our “Retrieve Documents” activity. Here, I am retrieving based on only one condition, i.e., Pick Up point is Chennai.

Retrieve Documents-2

  • Upon starting the instance, we will be able to see response as below:
MongoDB Blog-RD3
  • Now, let’s try retrieving with multiple conditions. For that we have to provide the Filters in an Array of JSON, where each JSON has the keys - colName, operator, value. The default logicalOperator is AND, but can be overriden with OR, NOT explicitly. Operator also supports the valid commonly used operators like =, >=, <=, !=, like(for Regular Expressions), in, not in. But the default is “=” is the operator given is invalid.
  • In the following JSON that is inputted in the Filters field, I am using a complex filter (a combination of filters). Here I am asking the connector to retrieve only the documents that has the PickUp points values that matches the regular expression “contains “bad” as substring“, and the values are in the given array, and then I am applying NOT operator to negate the resultset.
MongoDB Blog-RD4
  • Moving forward to starting an instance, we are able to notice that no documents that with PickUp points containing substring “bad”, or from Kochi and Bengaluru are retrieved.
MongoDB Blog-RD5

Retrieval with Sorting :

  • Let’s consider the previous filter set itself, and try to sort the resultset on the basis of Number_Of_Seats booked. So, in the OrderBy menu, I am required to give the following JSON.
MongoDB Blog-RD6
  • Upon deploying the process and starting the instance, I am able to get the following resultset. If, instead of “desc”, have we given “asc” in the order field, the resultset would have been reversed.
MongoDB Blog-RD7

Retrieval with Limits :

  • Let's move on with the times when we need to retrieve only limited amount of data, rather than the full data, just to analyze a pattern of bookings. Limit function will save our day in this case. This limit option intakes integer values, and retrieve that many number of records.
Retrieve Document-4
  • We got this output from the connector, after performing the operations we desired.
MongoDB Blog-RD8
  • Okay, now let's play the large game and implement all these features together. Here is the screenshot of my modeler.
Retrieve Document-5
  • And, this is the output that we have got.
MongoDB Blog-RD9

In this instalment, we've explored the art of retrieving data from MongoDB collections. By harnessing the power of filtering, sorting, and limiting, we’re now able to precisely extract the information you need. This knowledge forms a crucial foundation as we move forward in our journey through MongoDB.

In the upcoming final part of this series, we will cover the remaining key operations: updating and deleting documents, dropping collections, and even saying goodbye to a database if needed. Armed with these skills, we'll have a good grasp to manage our data present MongoDB effectively using our custom outbound Camunda connector.

Contact :

More to explore