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

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

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.