This scenario describes a Job that writes the information of books into a CouchDB database, replicates the data to the target database, and then displays some replicated information of interest on the console.
Drop the following components from the Palette onto the design workspace: tCouchDBConnection, tFileInputDelimited, tCouchDBOutput, tCouchDBInput, tLogRow and tCouchDBClose.
Connect tFileInputDelimited to tCouchDBOutput using a Row > Main link.
Do the same to connect tCouchDBInput to tLogRow.
Connect tCouchDBConnection to tFileInputDelimited using a Trigger > OnSubjobOk link.
Do the same to connect tFileInputDelimited to tCouchDBInput and tCouchDBInput to tCouchDBClose.
Label the components to better identify their functions.
Opening a CouchDB connection and triggering replication
Double-click the tCouchDBConnection component to open its Basic settings view in theComponent tab.
In the Server and Port fields, type in the connection details.
In the Database field, type in the name of the database you want to use: bookstore_old in this example.
Select the CouchDB version that you are using from the DB Version list.
Select the Use trigger replication check box.
In the Replicate target database area, click [+] to add one line for database replication settings.
Enter the name of the target database name: bookstore_new in this example.
Select the Continuous check box to continue the replication upon the server restart.
In this example, the target database does not exist. Select the Create target DB check box to create the target database.
Select the Is Canceled check box to cancel the replication between bookstore_old and bookstore_new at the end of the Job.
Reading the input data
Double-click the tFileInputDelimited component to open its Component view.
Click the [...] button next to the File name/Stream field to browse to the file that you want to read data from. In this scenario, it is D:/Input/bookstore.txt. The file contains six columns: _id, title, author, category, ISBN, and abstract.
_id;title;author;category;ISBN;abstract 001;Computer Networks: A Systems Approach;Larry L. Peterson, Bruce S. Davie;Computer Science;0123850606;This best-selling and classic book teaches you the key principles of computer networks with examples drawn from the real world of network and protocol design. 002;David Copperfield;Charles Dickens;Language&Literature;1555763227;This adaptation of the original story is presented in the format of a novel study, complete with exercises and vocabulary lists, and is geared to the language arts classes of grades 4 and 5. 003;Life of Pi;Yann Martel;Language&Literature;0547350651;The son of a zookeeper, Pi Patel has an encyclopedic knowledge of animal behavior and a fervent love of stories. 004;Les Miserables: Easyread Comfort Edition;Victor Hugo;Language&Literature;1425048250;Expressing the author's ideas about society, religion and politics, it is in the backdrop of Napoleonic Wars and ensuing years that the story unravels. Grace, moral philosophy, law and history of France are discussed. 005;Computer Security;Dieter Gollmann;Computer Science;0470741155;This text moves away from the 'multi-level' security approach to compare and evaluate design alternatives in computer security. 006;Advanced Database Systems;Carlo Zaniolo;Database;155860443X;This book, written by a team of leading specialists in their fields, introduces the research issues at the forefront of database technology and supports them with a variety of examples.
In the Header field, type in 1 so that the header of the file will be skipped.
Click Edit schema to define the data to pass on to the tCouchDBOutput component.
Writing data into one database and replicating the data
Double-click the tCouchDBOutput component to open its Basic settings view in the Component tab.
Click Sync columns to retrieve the schema from the preceding component.
Select the Use an existing connection check box. In this example, the replication is triggered when opening the CouchDB connection.
Select Upsert from the Action on data drop-down list.
Extracting the replicated data of interest
Double-click the tCouchDBInput component to open its Component view.
Click Edit schema to define the data structure to be read from the CouchDB database.
By default, the Include docs check box is selected, so the id, key, value and jsonDoc columns are available in the schema.
In this example, we define four columns to be extracted: id, title, author and category.
Enter the Server and Port information.
In the Database field, enter the name of the database from which the replicated data will be read. In this example, it is bookstore_new.
In the Querying options area, type in the start key and end key to set the range of the data to be read: "001" and "006" in this example.
Select the Extract JSON field check box to extract the desired data.
Select jsonDoc from the JSON field list.
In the Mapping area, click [+] to add items. Select the schema output column from the list and then type in the proper XPath query.
Displaying the extracted data
Double-click the tLogRow component to open its Component view.
Click Edit schema to define the data structure to be displayed on the console. In this example, we need to remove the jsonDoc column.
In the Mode area, select Table (print values in cells of a table).