Read Files From MongoDB With Talend
To follow this procedure, you must have a Repository containing the information of the Saagie platform. To this end, create a context group and define the contexts and variables required.
In this case, define the following context variables:
Name | Type | Value |
---|---|---|
|
String |
Your MongoDB IP address |
|
String |
Your MongoDB port |
|
String |
Your MongoDB database |
|
String |
Your MongoDB collection |
|
String |
The MongoDB user authentication name |
|
String |
The MongoDB user account password |
Once your context group is created and stored in the Repository, you can apply the Repository context variables to your jobs.
For more information, read the whole section on Using contexts and variables on Talend Studio User Guide. |
This tutorial is an example of how to count lines. |
-
Create a new job in Talend.
-
Add the following components:
-
tMongoDBConnection
, to create a connection to a MongoDB database and reuse that connection in other components. -
tMongoDBInput
, to extract data from the MongoDB database collection and send the data to the following component. -
tAggregateRow
, to receive a flow and aggregate it based on one or more columns. -
tLogRow
, to display the result.
-
-
Link these components as follows:
-
Link
tMongoDBConnection
andtMongoDBInput
with theOnSubjobOk
connection. -
Link
tMongoDBInput
andtAggregateRow
with theMain
connection. -
Link
tAggregateRow
andtLogRow
with theMain
connection.
-
-
Double-click each component and configure their settings as follows:
In the Basic settings tab:
-
From the DB Version list, select your database version.
-
In the Server and Port fields, enter the IP address and listening port of the database server.
Available when the Use replica set address option is not selected. -
In the Database field, enter the name of the database.
-
Select the Required authentication option to enable the database authentication.
-
In the Authentication mechanism list, select the authentication mechanism the most adapted to the MongoDB version you are using.
The NEGOTIATE
mechanism is recommended if you are not using Kerberos. -
In the Username and Password fields, enter the database user authentication data.
Available when the Required authentication option is selected.
For more information, you can refer to Talend’s documentation on the tMongoDBConnection
component.In the Basic settings tab:
-
Select the Use an existing connection option.
-
From the Component List list, select the connection component
tMongoDBConnection
to reuse the connection details already defined. -
In the Database field, enter the name of the database.
-
Click Edit schema to make changes to the schema, which defines the number of columns to be processed and passed on to the next component.
-
In the Query field, you can enter your query.
For more information, you can refer to Talend’s documentation on the tMongoDBInput
component.In the Basic settings tab:
-
Click Edit schema to make changes to the schema, which defines the number of columns to be processed and passed on to the next component. Add the
sum
column as output. -
In the Operations field, select the type of operation along with the value to use for the calculation, and the output field.
For more information, you can refer to Talend’s documentation on the tAggregateRow
component.For more information, you can refer to Talend’s documentation on the tLogRow
component. -
-
Run the job.