tMongoDBRow

One Star

tMongoDBRow

Hi all,
I've been scratching my head on this one;
How do I get the output of the command I run in tMongoDBRow for use in the next component?
Here's what needs to be done:
I get a list of (qualifying) entries from MongoDB via the tMongoDBInput, I use the "Name" column from the results to do a fts search via the tMongoDBRow component, for example:
Function: "db.compds.runCommand('text', {search: '" + row1.Name + "', filter: {'ClassId':'SOFTWARESERVER'}, project: {ReconId: 1}})"
Then, I would ideally have a tExtractJSONFileds component to extract the "score" and "ReconId" from the ^resultset for further decisioning and processing.
Any solution to accomplish this would be appreciated, it doesn't have to be the tMongoDBRow component.
Regards and happy holidays,
Johan.
Community Manager

Re: tMongoDBRow

Hi Johan
When I look into the generated code of tMongoDBRow component, I see that this component do not assign command result to a schema column, except printing the result on the console.
		com.mongodb.CommandResult result_tMongoDBRow_1 = null;
result_tMongoDBRow_1 = db_tMongoDBRow_1
.doEval("function(name,age){ return db.person.save({name:name,age:age});}",
row1.name, row1.age);
if (result_tMongoDBRow_1.ok()) {
System.out.println(result_tMongoDBRow_1);
} else {
System.err.println(result_tMongoDBRow_1);
}

So, you can't use tMongoDBRow to search records from MongoDB now.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tMongoDBRow

Four Stars

Re: tMongoDBRow

The MongoDB driver is still very poor.

As a workaround, you can use a tJavaFlex to use the MongoDB database object and do anything you want.

Here's an example of a tJavaFlex that get custom indexes, drop and returns them in output.

This code assumes you have added a tMongoDbConnection named "tMongoDBConnection_1", so its db object is named "db_tMongoDBConnection_1" (you will find this in the "code" tab).

 

Advanced settings > Import :

 

import com.mongodb.client.MongoDatabase;
import com.mongodb.util.JSON;
import java.util.ListIterator;
import java.util.ArrayList;

Basic settings > Main code :

 

MongoDatabase database = (MongoDatabase)globalMap.get("db_tMongoDBConnection_1");
org.bson.Document indexesResult = database.runCommand(new org.bson.Document("listIndexes", context.collection));
ArrayList indexes = (ArrayList)((org.bson.Document)indexesResult.get("cursor")).get("firstBatch");
ListIterator<org.bson.Document> iter = indexes.listIterator();
org.bson.Document indexDoc;

while (iter.hasNext()) {
  indexDoc = iter.next();
  if (indexDoc.getString("name").equals("_id_")) {
    iter.remove();
  }
  else {
    indexDoc.remove("v");
    indexDoc.remove("ns");
  }
}
row1.indexes = JSON.serialize(indexes);
database.runCommand(new org.bson.Document(routines.Mongo.formatDropIndexesCommand(context.collection)));

Then in the tJavaFlex schema, I added a "indexes" String field.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog