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

Figure 1 shows the MongoDB properties without enabling the Show Expert Properties check box.


Figure 1: Component Configuration

Attributes

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 insert like operations, 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 required operation name in 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:

Type of QueryDescription

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 sections below.

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 on 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
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
  • True: Creates a new document if no document matches the query, or if document matches the query, performs an update.
  • False: New document is not created in case update condition is not matched.
Update multiple documents
  • True: Updates all documents which matches with the query condition.
  • False: 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" for details 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 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. The 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

Input Schemas for Insert operation 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

Input Schemas for Update operation 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 or equal to 70. 

Output for the Update operation


Figure 15: Output for the update operation

Input for Delete operation

Input Schemas for Delete operation 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 Selectoperation

Input Schemas for Select operation 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 ease of use.

Adaptavist ThemeBuilder EngineAtlassian Confluence