tMongoDBRow - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

Warning

This component will be available in the Palette of Talend Studio on the condition that you have subscribed to one of the Talend solutions with Big Data.

tMongoDBRow Properties

Component family

Big Data / MongoDB

 

Function

tMongoDBRow executes the commands and functions provided by the MongoDB database.

Purpose

This component allows you to execute the commands and functions of the MongoDB database.

Basic settings

Use existing connection

Select this check box and in the Component List click the relevant connection component to reuse the connection details you already defined.

 

DB Version

List of the database versions.

Available when the Use existing connection check box is not selected.

 

Use replica set address

Select this check box to show the Replica address table.

In the Replica address table, you can define multiple MongoDB database servers for failover.

Available when the Use existing connection check box is not selected.

 

Server and Port

Address and listening port of the database server.

Available when the Use existing connection or Use replica set address check box is not selected.

 

Database

Name of the database.

 

Use SSL connection

Select this check box to enable the SSL encrypted connection.

Then you need to use the tSetKeystore component in the same Job to specify the authentication information.

For further information about tSetKeystore, see tSetKeystore.

Note that the SSL connection is available only for the version 2.4 + of MongoDB.

 

Required authentication

Select this check box to enable the database authentication.

 

Username and Password

DB user authentication data.

To enter the password, click the [...] button next to the password field, and then in the pop-up dialog box enter the password between double quotes and click OK to save the settings.

Available when the Required authentication check box is selected.

If the security system you have selected from the Authentication mechanism drop-down list is Kerberos, you need to enter the User principal, the Realm and the KDC server fields instead of the Username and the Password fields.

 

Schema and Edit Schema

A schema is a row description. It defines the number of fields (columns) to be processed and passed on to the next component. The schema is either Built-In or stored remotely in the Repository.

Click Edit schema to make changes to the schema. If the current schema is of the Repository type, three options are available:

  • View schema: choose this option to view the schema only.

  • Change to built-in property: choose this option to change the schema to Built-in for local changes.

  • Update repository connection: choose this option to change the schema stored in the repository and decide whether to propagate the changes to all the Jobs upon completion. If you just want to propagate the changes to the current Job, you can select No upon completion and choose this schema metadata again in the [Repository Content] window.

Click Sync columns to retrieve the schema from the previous component connected in the Job.

 

Execute command

Select this check box to enter MongoDB commands in the Command field for execution.

  • Command: in this field, enter the command to be executed, if this command contains one single variable.

    For example, if you need to construct the command

    {"isMaster": 1}

    You need simply enter isMaster within quotation marks.

  • Construct command from keys and values: if the command to be executed contains multiple variables, select this check box and in the Command keys and values table, add the variables and their respective values to be used.

    For example, if you need to construct the following command

    { renameCollection : "<source_namespace>" , to : "<target_namespace>" , dropTarget : < true | false > }

    You need to add three rows to the Command keys and values table and enter one variable-value pair to each row within quotation marks:

    "renameCollection"      "old_name"
    "to"                    "new_name"
    "dropTarget"            "false"

 

Function

Enter MongoDB functions in the Function field for execution.

Not available when the Execute command check box is selected.

 

Parameters value

Click the [+] button to add lines as needed and then define the parameter values in the form of variables or constant values, for example row1.author or "Andy". Note that the parameter values correspond to the parameters defined in the Function field, in the same order.

Not available when the Execute command check box is selected.

 

Die on error

This check box is cleared by default, meaning to skip the row on error and to complete the process for error-free rows.

Advanced settings

tStatCatcher Statistics

Select this check box to collect the log data at the component level.

Global Variables

ERROR_MESSAGE: the error message generated by the component when an error occurs. This is an After variable and it returns a string. This variable functions only if the Die on error check box is cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl + Space to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio User Guide.

Usage

tMongoDBRow allows you to manipulate the MongoDB database through the MongoDB commands and functions.

Log4j

If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

n/a

Scenario: Using MongoDB functions to create a collection and write data to it

This scenario creates the collection blog and writes post data to it through the MongoDB functions.

Linking the components

  1. Drop tMongoDBConnection, tFixedFlowInput, tMongoDBRow, tMongoDBClose, tMongoDBInput and tLogRow onto the workspace.

  2. Rename tFixedFlowInput as blog_post_data, tMongoDBRow as write_data_to_collection, tMongoDBInput as read_data_from_collection and tLogRow as show_data_from_collection.

  3. Link tMongoDBConnection to tFixedFlowInput using the OnSubjobOk trigger.

  4. Link tFixedFlowInput to tMongoDBRow using a Row > Main connection.

  5. Link tFixedFlowInput to tMongoDBInput using the OnSubjobOk trigger.

  6. Link tMongoDBInput to tMongoDBClose using the OnSubjobOk trigger.

  7. Link tMongoDBInput to tLogRow using a Row > Main connection.

Configuring the components

  1. Double-click tMongoDBConnection to open its Basic settings view.

  2. From the DB Version list, select the MongoDB version you are using.

  3. In the Server and Port fields, enter the connection details.

    In the Database field, enter the name of the MongoDB database.

  4. Double-click tFixedFlowInput to open its Basic settings view.

    Select Use Inline Content (delimited file) in the Mode area.

    In the Content field, enter the data to write to the MongoDB database, for example:

    Andy;Open Source Outlook;Open Source,Talend;Talend, the leader of the open source world...
    Andy;Data Integration Overview;Data Integration,Talend;Talend, the leading player in the DI field...
    Andy;ELT Overview;ELT,Talend;Talend, the big name in the ELT circle...
  5. Double-click tMongoDBRow to open its Basic settings view.

    Select the Use existing connection check box.

    In the Function field, enter the MongoDB function to create the collection blog and insert data to it:

    "function(author,title,keywords,contents){
    return db.blog.save(
    {author:author,title:title,keywords:keywords,contents:contents}
    );
    
    }"
  6. Click the [...] button next to Edit schema to open the schema editor.

  7. Click the [+] button to add four columns in the right part, namely author, title, keywords and contents, with the type of String.

    Click to copy all the columns to the input table.

    Click OK to close the editor.

  8. In the Parameters value table, click the [+] button to add four lines and enter the values in sequence: row1.author, row1.title, row1.keywords and row1.contents. By doing so, data of row1 will be transferred to the parameters defined in the function.

  9. Double-click tMongoDBInput to open its Basic settings view.

    Select the Use existing connection check box.

    In the Collection field, enter the name of the collection, namely blog.

  10. Click the [...] button next to Edit schema to open the schema editor.

  11. Click the [+] button to add four columns, namely author, title, keywords and contents, with the type as String.

    Click OK to close the editor.

  12. Double-click tLogRow to open its Basic settings view.

    In the Mode area, select Table (print values in cells of a table for better display.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 to run the Job.