Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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.
Labels (2)
3 Replies
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

Anonymous
Not applicable
Author

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.