August 17, 2023

tMongoDBInput – Docs for ESB 5.x

tMongoDBInput

tMongoDBInput_icon32_white.png

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.

tMongoDBInput Properties

Component family

Big Data / MongoDB

 

Function

tMongoDBInput retrieves certain
documents from a MongoDB database collection by supplying a query
document containing the fields the desired documents should match.

Purpose

This component allows you to retrieve records from a collection in
the MongoDB database and transfer them to the following component
for display or storage.

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

IP 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.

 

Set read preference

Select this check box and from the Read preference
drop-down list that is displayed, select the member you want the Job to read from the
MongoDB replica set to be used.

If you leave this check box clear, the Job reads the default member of the replica
set.

For further information, see MongoDB’s documentation about Replication and its Read
preferences.

 

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.

 

Collection

Name of the collection in the MongoDB database.

 

Schema and Edit
Schema

A schema is a row description. It defines the number of fields 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.

 

Query

Specify the query condition.

For example, type in "{id:4}" to retrieve the record
whose id is 4 from the collection specified in the
Collection field.

Note

Different from the query statements required in the MongoDB
client software, the query here refers to the contents inside
find(), such as the query here
{id:4} versus the MongoDB client query
db.blog.find({id:4}).

 

Mapping

Specify the parent node for the column in the MongoDB
database.

 

Sort by

Specify the column and choose the order for the sort
operation.

 

Limit

Type in the maximum number of records to be retrieved.

Advanced settings

tStatCatcher Statistics

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

Global Variables

NB_LINE: the number of rows read by an input component or
transferred to an output component. This is an After variable and it returns an
integer.

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

As a start component, tMongoDBInput allows you to retrieve records from a
collection in the MongoDB database and transfer them to the
following component for display or storage.

Log4j

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.

Scenario: Retrieving data from a collection by advanced queries

In this scenario, advanced MongoDB queries are used to retrieve the post by the author
Anderson.

There are such posts in the collection blog of the
MongoDB database talend:

use_case_tmongodbinput_1.png

To insert data into the database, see Scenario 1: Creating a collection and writing data to it.

Linking the components

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

  2. Link tMongoDBConnection to tMongoDBInput using the OnSubjobOk trigger.

  3. Link tMongoDBInput to tMongoDBClose using the OnSubjobOk trigger.

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

    use_case_tmongodbinput_2.png

Configuring the components

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

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

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

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

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

    use_case_tmongodbinput_4.png
  6. Select the Use existing connection
    option.

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

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

    use_case_tmongodbinput_5.png
  9. Click the [+] button to add five columns,
    namely id, author, title, keywords and contents, with the type as Integer and String
    respectively.

  10. Click OK to close the editor.

  11. The columns now appear in the left part of the Mapping area.

  12. For columns author, title, keywords and contents,
    enter their parent node post so that the
    data can be retrieved from the correct positions.

  13. In the Query box, enter the advanced
    query statement to retrieve the posts whose author is Anderson:

    This statement requires that the sub-node of post, the node author,
    should have the value “Anderson”.

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

    use_case_tmongodbinput_6.png

    Select Table (print values in cells of a
    table)
    for a better display of the results.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 to run the Job.

    use_case_tmongodbinput_7.png

    As shown above, the post by Anderson is retrieved.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x