Scenario 2: Querying JSON documents in the Couchbase database through view queries - 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

This scenario queries the JSON documents through view queries. Specifically, we combine the View queries and some other filters to retrieve the document information. For the View part, we define the map function where the Key is specified as the id field of the documents while the Value is specified as the title and contents fields. The documents in the Couchbase database are shown below:

For how to write such documents to the database, see Scenario: Inserting documents to a data bucket in the Couchbase database.

Linking the components

  1. Drop tCouchbaseConnection, tCouchbaseInput, tCouchbaseClose and tLogRow onto the workspace.

  2. Link tCouchbaseConnection to tCouchbaseInput using the OnSubjobOk trigger.

  3. Link tCouchbaseInput to tLogRow using a Row > Main connection.

  4. Link tCouchbaseInput to tCouchbaseClose using the OnSubjobOk trigger.

Configuring the components

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

  2. In the Data Bucket field, enter the name of the data bucket in the Couchbase database.

  3. In the Password field, enter the password for access to the data bucket.

  4. In the URIs table, click the [+] button to add lines as needed, where you can enter the URIs of the Couchbase server nodes.

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

  6. Select the Use existing connection check box to reuse the connection.

  7. Select the Query by view check box to define the View functions and other filters.

  8. In the Design document field, enter the design document name of the View.

    In the Doc action list, select Drop create to remove an existing design document and create it again.

    In the View field, enter the name of the View.

    In the View action list, select Create to create the View.

  9. In the Map box, enter Map function:

    "function (doc, meta) {emit(doc.id, [doc.title,doc.contents]);}"

    Where, the Key is doc.id, namely the id field of the JSON documents and the Value is [doc.title,doc.contents], namely the title and contents fields of the JSON documents.

  10. Click the Edit schema button to open the schema editor. The schema contains four pre-defined fields, Id, Key, Value and jsonDoc.

    In this scenario, Id holds the document ID, Key holds the id field of the JSON documents, Value holds the title and contents fields of the JSON documents and jsonDoc holds the entire JSON documents.

  11. Select the Include docs check box to retrieve the entire documents.

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

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

  3. Go to the Couchbase web console and check the View created:

    As shown above, the View is created and the document information is correctly fetched.