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 tMongoDBConnectionandtMongoDBInputwith theOnSubjobOkconnection.
- 
Link tMongoDBInputandtAggregateRowwith theMainconnection.
- 
Link tAggregateRowandtLogRowwith theMainconnection.
  
- 
- 
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 NEGOTIATEmechanism 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 tMongoDBConnectioncomponent.In the Basic settings tab: - 
Select the Use an existing connection option. 
- 
From the Component List list, select the connection component tMongoDBConnectionto 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 tMongoDBInputcomponent.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 sumcolumn 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 tAggregateRowcomponent.For more information, you can refer to Talend’s documentation on the tLogRowcomponent.
- 
- 
Run the job.