Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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);
}
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.