• fb
  • tw
  • gg
97008 48403
+91 40-27177600

Blog

How to construct a DW field to use the $gte operator on a date field in Mule ESB

single-blog

From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog talks about constructing a DW field to use the $gte operator on a date field in Mule ESB. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.

In one of our projects we have come across the following scenario, where we are able to retrieve documents from a specific time using syntax like :getCollection(‘events’).find({ whenOccurred: {$gte: new Date(ISODate().getTime() – 1000 * 60 * 60 * 24 * 120) }}), when it comes to Mule ESB, we had to struggele to find a way to construct a DW field to use the $gte operator on a date field.

What is MongoDB?

From the source website, we define MongoDB as a document database with the scalability and flexibility that you want with the querying and indexing that you need.

MongoDB is an open-source, document database designed for ease of development and scaling. The Manual introduces key concepts in MongoDB, presents the query language, and provides operational and administrative considerations and procedures as well as a comprehensive reference section.

MongoDB is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster.

Getting Started with Mongo DB:

Download Link :- https://www.mongodb.com/download-center?jmp=nav#community

Install the Mongo DB in your system. check the program files for Mongo DB as shown in the example below

ex: C:\Program Files\MongoDB\Server\3.4\bin

Note: Before running the Mongo DB create a folder data & DB folder in data in C Drive ex: C:\data\db

How to Start:

Open a command prompt and paste the path up to bin (i.e. C:\Program Files\MongoDB\Server\3.4\bin). Execute the code mongod run Mongo DB

2) Connect to the instance: mongo –port 27017

3) Create the user administrator (in the admin authentication database) as shown:

use admin

db.createUser(

{

user: “myUserAdmin”,

pwd: “abc123”,

roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ]

}

)

4) Re-start the MongoDB instance with access control: mongod

5) Connect and authenticate as the user administrator as shown:

mongo –port 27017 -u “myUserAdmin” -p “abc123” –authenticationDatabase “admin”

6) Create additional users as needed for your deployment (in the test authentication database).

use test

db.createUser(

{

user: “myTester”,

pwd: “xyz123”,

roles: [ { role: “readWrite”, db: “test” },

{ role: “read”, db: “reporting” } ]

}

)

7) Connect and authenticate as myTester.

  • mongo –port 27017 -u “myTester” -p “xyz123” –authenticationDatabase “test”

Now, we will do the Question in Anypoint Studio in a step-by-step approach

Step 1: Create a project and search http listener in Mule ESB Palette and drag it to the Message flow and configure as follows

Step 2:- Drag a variable to the flow and set the variable with the data as we want to get the data from data base based on the date.

Step 3:-Now, Drag a set payload to the message flow & write a code in it to get the data based on it.

Step 4:- Drag a Mongo DB connector to the message processor from Mule palette, configure the Mongo DB as follows:

Step 5: Complete flow in Mule ESB is here.

Step 6: Run the project and after successful deployment hit the postman to see the results

Hence, we have gone through the step by step process to depict the way Massil Technologies team has addressed the above-mentioned scenario. Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to info@massil.tech.

Leave a Reply

Your email address will not be published. Required fields are marked *

map

Contact Us

Get in touch with us