Docs‎ > ‎REST APIs‎ > ‎Data Integration‎ > ‎MongoDB Integration‎ > ‎

MongoUtility

The MongoUtility.js is a JavaScript library that is available as a wrapper to support and demonstrate using the MongoDB Java Driver.

Step 1. - Enable the MongUtility.js script by selecting (used) in the Project/Library section.

 


Step 2. - Configure the server properties as a JSON expression

var configSetup = {
   serverName  : 'localhost',
   serverPort  : '27017' ,
   databaseName: 'Audit'
};

Step 3- Create a new instance of the Utility in your JavaScript code and pass in the setup configuration from step 2.

var mongoClient = MongoUtilityCreate();
mongoClient.configure(configSetup);

Step 4 - Create a connection to the server (and optional security logon)


var payload = {
    username: "demo",
    password: "Password1"
};

var DB = mongoClient.createClientConnection(payload);


Query Function: Execute a query on a specific collection and return an array of results

var collectionName = "MyCollection';
var query = {name: 'foo'};
var array =runMongoQuery(collectionName, query, {}, {}, 10, 0) ;//collectionName, query, columns, sort, limit, offset

Insert Function: Insert a JSON collection into Mongo Collection

var payload= logicContext.rowToJSON(row);
var result = mongoClient.mongoInsert("audit","EspressoAudit", payload);

Close the connection

mongoClient.close();

The sample programs are attached to demonstrate how to wrap JavaScript around existing Java.
ċ
MongoUtility.js
(2k)
Unknown user,
Aug 27, 2014, 6:52 PM
ċ
test.js
(1k)
Unknown user,
Aug 27, 2014, 6:52 PM
Comments