MongoDB component can be used to insert, update, delete and select data from Mongo database server.
Component supports both JSON and XML data in request as well as response.
Configuration
Attributes
Figure 1 shows the MongoDB properties without enabling the Show Expert Properties check box.
Figure 1: Component Configuration
Connection Configuration
Click the Connection Configuration ellipsis button to set up the configuration required to connect to MonogDB server.
Figure 2: Connection Configuration
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.
Query Configuration
Figure 3: Query Configuration
Any of the CRUD operations can be configured by clicking 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 Query | Description |
---|---|
INSERT | Inserts data into database collection |
UPDATE | Modifies existing data in database collection |
DELETE | Deletes data from database collection |
SELECT | Retrieves data from database collection |
Collection
Collection name in the database on which operation is to be performed. For Insert and Update queries, if 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 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: Right click menu on a field in 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 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
Up: Moves the selected field above the previous field.
Down: Moves the selected field below the next field.
UPDATE
Figure 9: 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
Operator | Description |
---|---|
SET | Sets the value of a field in a document. |
UNSET | Removes the specified field from a document. |
INCREMENT | Increment field by a specified value. |
MULTIPLY | Multiplies the value of the field by the specified amount. |
RENAME | Renames a field. |
MINIMUM | Only updates the field if the specified value is less than the existing field value. |
MAXIMUM | Only updates the field if the specified value is greater than the existing field value. |
PUSH | Adds an item to an array. |
CURRENT_DATE | Sets the value of a field to current date, either as a Date or a Timestamp. |
Update Condition field operators
Operator | Description |
---|---|
GREATER_THAN | Selects those documents where the value of the field is greater than (i.e. >) the specified value. |
GREATER_OR_EQUAL | Selects the documents where the value of the field is greater than or equal to (i.e. >=) a specified value |
LESSER_THAN | Selects the documents where the value of the field is less than (i.e. <) the specified value |
LESSER_OR_EQUAL | Selects the documents where the value of the field is less than or equal to (i.e. <=) the specified value. |
NOT_EQUAL | Selects the documents where the value of the field is not equal (i.e. !=) to the specified value |
IN | Selects the documents where the value of a field equals any value in the specified array. |
NOT_IN | Selects the documents where:
|
Upsert |
|
Update multiple documents |
|
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.
DELETE
Figure 10: 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 11: 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 12: Input to insert 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.
XML
Displays the output in XML format.
Sample Flow
Figure 13: Sample flow of MongoDB
Input and Output
Input for Insert operation
Insert operation Input Schemas for different JSON values are given below.
If Set to false
If Set to true
Output for the Insert operation
Figure 14: Output for insert operation
Input for Update operation
Update operation Input Schemas for different JSON values are given below.
If Set to false
If 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 15: Output for the update operation
Input for Delete operation
Delete operation Input Schemas for different JSON values are given below.
If Set to false
If Set to true
Output for the Delete operation
Figure 16: Output for delete operation
Input for Select operation
Select operation Input Schemas for different JSON values are given below.
If Set to false
If Set to true
Displays the "_id" and "type" fields in the documents which has "qty" field greater than 70.
Empty value in the fields section retrieves all the fields in the documents which are satisfying the condition.
Output for the Select operation
Figure 17: 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.