MongoDB component can be used to insert, update, delete and select data from Mongo database server.

The component supports both JSON and XML data in request as well as response.

Configuration

Attributes

The figure shows the MongoDB properties without enabling the Show Expert Properties check box.


Figure 1: MongoDB Component Configuration CPS

Connection Configuration

Click the Connection Configuration ellipsis button to set up the configuration required to connect to the MonogDB server.


Figure 2: Connection Configuration dialog box

Database Host(s)

A list of primary and secondary (if present) database servers' host and port details in the form of <host>:<port> can be provided here.

Database Name

Name of the database in the server to perform operations on. For operations like Insert, if there is no database with the given name, it will be created by the component.

Username

Login username for the server.

Password

Password associated with the username provided.

Connection Timeout (in ms)

The timeout in milliseconds until a connection is established. A value is 0 means no timeout.

Connection String

Additional Connection String to specify additional connection options. Each connection option is specified as a pair in the following form: name=value.

Icon
  • The value is case sensitive.
  • Separate the options with ampersand (&) character.
Icon

For a complete list of connection string options, please refer to the following link:
https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options

Query Configuration

Click the Query Configuration ellipsis button to set up the configuration required to add queries.


Figure 3: Query Configuration dialog box

Any of the CRUD operations can be configured by clicking the Add button and selecting the required operation name from the menu. A Query with default Query Name and Query Type is added to the list of queries.

Query Name

Name of the query to be executed. It should not be empty.

Query Type

Displays query type of the query. This field cannot be edited. The operations supported are described in the below table.

Type of QueryDescription

INSERT

Inserts data into the database collection

BULKINSERTInserts multiple documents into the database collection

UPDATE

Modifies existing data in the database collection

DELETE

Deletes data from the database collection

SELECT

Retrieves data from the database collection

Collection

Collection name in the database on which operation is to be performed. For Insert and Update queries, if the collection specified does not exist, a new collection with the same name will be created. 

JSON

If set to true, the input is expected in the form of JSON string else it is expected in XML format. This is demonstrated in the following sections.

Add

This button generates a list of query type which can be used for querying to the MongoDB server.

Delete

This button is used to delete a query from the query list. The query selected will be removed from the list.

Delete All

This button deletes all the queries in the query list. 

INSERT


Figure 4: Insert Query Configuration

Right-click the empty space in the element-type table to add a key to insert the required field in the document.

 
Figure 5: Adding a new field to Element-Type table


Figure 6: Context menu on a field in the Element-Type table

Add Child: Adds a node to the parent node. Refer to http://docs.mongodb.org/manual/tutorial/model-tree-structures-with-child-references/ for further details.

Add Key: Adds another node to the table.

Delete: The selected field will be deleted on clicking this button.


Figure 7: Adding children to a parent node in the Element-Type Table

This structure will generate a document of the form {"key1": {"child1":"val", "child2":"val"}, "key2" : "val"}.

Refer to section "Input and output" for further details about the input.


Figure 8: Up-Down buttons to change the order of elements

Up: Moves the selected field above the previous field.

Down: Moves the selected field below the next field. 

BULKINSERT


Figure 9: Bulk Insert Query configuration

This operation is used to insert multiple documents into a collection. A JSON array can be specified to list the documents to be inserted.

Refer to the Input and Output section for the sample input and its output. In the Query Configuration window, provide a Collection name, and set JSON to "true" so that JSON array can be specified in the input to insert multiple documents into the specified collection.

UPDATE


Figure 10: Update Query configuration

Fields present in the first element-type-operator are updated if conditions specified in the second table are met.

Update field Operators
OperatorDescription
SETSets the value of a field in a document.
UNSETRemoves the specified field from a document.
INCREMENTIncrement field by a specified value.
MULTIPLYMultiplies the value of the field by the specified amount.
RENAMERenames a field.
MINIMUMOnly updates the field if the specified value is less than the existing field value.
MAXIMUMOnly updates the field if the specified value is greater than the existing field value.
PUSHAdds an item to an array.
CURRENT_DATESets the value of a field to current date, either as a Date or a Timestamp. 
Update Condition field operators
OperatorDescription
GREATER_THANSelects those documents where the value of the field is greater than (i.e. >) the specified value.
GREATER_OR_EQUALSelects the documents where the value of the field is greater than or equal to (i.e. >=) a specified value
LESSER_THANSelects the documents where the value of the field is less than (i.e. <) the specified value
LESSER_OR_EQUALSelects the documents where the value of the field is less than or equal to (i.e. <=) the specified value.
NOT_EQUALSelects the documents where the value of the field is not equal (i.e. !=) to the specified value
INSelects the documents where the value of a field equals any value in the specified array.
NOT_IN

Selects the documents where:

  • the field value is not in the specified array or
  • the field does not exist.
Upsert
  • Enabled: Creates a new document if no document matches the query, or if a document matches the query, performs an update.
  • Disabled: A new document is not created in case update condition is not matched.
Update multiple documents
  • Enabled: Updates all documents which match with the query condition.
  • Disabled: Updates only the first document that matches with the query.

The element to be updated is to be specified in the Element-Type table and query condition is to be specified in the Update Condition table.

Refer to section "Input and Output" to know about the effects of these configurations on input and output structures.

Icon

 Equality is considered by default when none of the operators are chosen.

DELETE


Figure 11: Delete Query Configuration 

Add a field which is to be removed from the documents and specify its data type.

For further information, go through the "input and output" section.

SELECT


Figure 12: Select Query configuration

The condition for the operation is to be specified in the Select Condition table. Fields to be retrieved should be specified in the Select Fields table. 

Select All Fields

Retrieves all the fields in the document which satisfies the query condition.

Select '_id' Field:

 _id field is also included in the output along with the retrieved fields.

For further information, go through the "input and output" section.

ARRAYS

We have many types of arrays like String[],Object[],Boolean[],Int[] etc which are to be selected from the cps to specify operations on that particular type.

Int []


Figure 13: Input to insert an array of type int[]

Input schema

Schema for the above insert operation

Output

Array with "key" : [ 123, 321, 456, 789 ] is added into the collection.

Output Type

JSON: Displays the output in the form of a JSON string.

XMLDisplays the output in XML format.

Expert Properties

Enable the Show Expert Properties checkbox to configure these properties.

 

Icon

Expert properties are meant for advanced users; use it with caution.


Figure 14: MongoDB CPS with the Expert properties enabled and highlighted

 

Validate Input

This property determines whether the input message has to be validated against the schema defined on the input ports.

Refer to the Validate Input section in the Common Configurations page.

Error Handling Configuration

The remedial actions to be taken when a particular error occurs can be configured here.

Please refer the Error Handling section in Common Configurations page for documentation.

Pre Processing XSL Configuration

Pre Processing XSL configuration can be used to transform request message before processing it. Click the ellipses button against the property to configure the properties.

Refer to the Pre/Post Processing XSL Configuration section in the Common Configurations page for details regarding Pre Processing XSL configuration and Post Processing XSL configuration (below).

Post Processing XSL Configuration 

Post Processing XSL configuration can be used to transform the response message before sending it to the output port.

Process Message Based on Property

The property helps components to skip certain messages from processing.

Refer to the Process Message Based On a Property section in the Common Configurations page.

Target Namespace

Refer to the Target Namespace section under the Common Configurations page.

Threadpool Configuration

 This property is used when there is a need to process messages in parallel within the component, still maintaining the sequence from the external perspective. 

Refer to the Threadpool Configuration section in the Common Configurations page.

Functional Demonstration

Connect a Feeder component to insert input to the MongoDB component and add a Display component to display the output.


Figure 15: Sample flow of MongoDB

Input and Output

Input for the Insert operation

Insert operation Input Schemas for different JSON values are given below. 

JSON set to false

JSON set to true

Output for the Insert operation


Figure 16: Output for the Insert operation

Input for Bulk Insert operation

JSON set to true

Output for Bulk Insert Operation

This will insert three documents into the collection specified in the Query Configuration window.


Figure 17: Output for the Bulk Insert operation

Input for the Update operation

Update operation Input Schemas for different JSON values are given below. 

JSON set to false

JSON set to true

It modifies the "type" field as juice in the documents for which the value of "qty" is greater than or equal to 70. 

Output for the Update operation


Figure 18: Output for the Update operation

Input for the Delete operation

Delete operation Input Schemas for different JSON values are given below. 

JSON set to false

JSON set to true

Output for the Delete operation


Figure 19: Output for the Delete operation

Input for the Select operation

Select operation Input Schemas for different JSON values are given below. 

JSON set to false

JSON set to true

Displays the "_id" and "type" fields in the documents which have "qty" field greater than 70.

An empty value in the fields section retrieves all the fields in the documents which are satisfying the condition.

Output for the Select operation


Figure 20: Output for Select operation

Points to note

  • Select output type XML for Insert, Update and Delete operations and JSON for Select operation for the ease of use.
  • While inserting fields of 'Date' data type, please ensure that the date is in the following format to avoid exceptions:


    Example

    Icon
    • "2018-09-25T17:09:58+0000" is a valid format.
    • "2018-09-25T17:09:58" is not a valid format.
Adaptavist ThemeBuilder EngineAtlassian Confluence