Wednesday, October 17, 2012

MongoDB, Part 2

So, I was able to get data from MongoDB collections pulled into datasets, and written back to datasets as well.  A little scripting was required.  I packaged it all up and attached it to this post.  Feel free to play around with it if you'd like.

There's 1 window and 1 script module to make this all work.  And, of course, make sure you grab the MongoDB module as well.

Project: MongoDB.proj

MongoDB Module: MongoDBDriver.modl

Note: There aren't any performance optimizations to this code.  Certainly, if you're thinking about using this in production, make sure to do a thorough code review and adjust it to act the way you need for your organization.

Ignition: 7.5 (7.5.3)

Friday, October 12, 2012

MongoDB in Ignition

I was recently asked whether Ignition supports NoSQL.  Well, NoSQL certainly isn't right for most things an Ignition system will be used for, but I thought I'd throw together a little proof-of-concept to show it could be done.

So, I present to you, MongoDB in Ignition!

It was really quite simple to make work (took 30 minutes).  Here's what I did:
1) Downloaded the MongoDB Java Driver from Mongo's website
2) Packaged it up as a module, telling it to load in all 3 contexts
3) Wrote a script based on

Here's my module.xml:
<?xml version="1.0" encoding="UTF-8"?>
  <name>MongoDB Driver</name>
  <description>The MongoDB Java Driver.</description>
  <!-- The MongoDB Java Driver libraries -->
  <jar scope="DCG">mongo-2.9.1.jar</jar>

After loading the module, you can simply use MongoDB from the Ignition Designer, Client, or Gateway.

Here's my testing script from my gateway:
from com.mongodb import Mongo

mongo = Mongo("localhost", 27017)
db = mongo.getDB("test")

testCollection = db.getCollection("test")
result = testCollection.findOne()
print result

Since I have MongoDB running on my system, the script above returned the first result found in the "test" collection, which was a:1.

Resulting Output:
{ "_id" : { "$oid" : "50787936a3513589171132bd"} , "a" : 1.0}

Simple as that. If you want a copy, follow the link below.

Download the module: MongoDBDriver.modl


Note: Using the module this way gives you a straight connection to your MongoDB from the Ignition Gateway, Client, or Designer.  If you're running a script in the client or designer, it does *not* forward the information through the gateway. (This is different than Ignition database connections, which forward all traffic through the gateway.)

Ignition Version: 7.5 (7.5.3)