(888) 685-3101 ext. 2

If you spend any time in blogs or in online I.T. press you hear Big Data, scalable solutions, and NoSQL databases all the time.  One popular NoSQL database solution is Mongo DB.

Mongo is “document-based”, not “table-based”.  It requires no pre-existing schema.  It creates document databases on-the-fly, with the first addition.  These let Mongo scale very well horizonally.

We’ll use Mongo to store some of the more transient data in Liferay: Custom Fields.  Specifically we’ll see how Mongo dynamically responds and stores Liferay User Profile custom fields.

Remember, Mongo houses “databases”.  Databases hold “collections”.  Collections hold “documents”.  Documents hold “fields”.  Fields are simply key/value pairs.

To do all of this, we altered Liferay’s “mongodb-hook”.  The original is in Liferay’s public Subversion respository.   We use the default Mongo port and specify a custom database instance.

Screen-Shot-2012-12-12-at-9.57.50-AM
When you deploy the hook, it will authenticate to Mongo and hold a connection.  As we see, our “mongo” database is not created.   Let’s create the Liferay Custom Field.

Screen-Shot-2012-12-12-at-10.04.39-AM

We created a Custom Field in Liferay’s User Profile.  Here users of our system record their “Favorite Ice Cream”.   Liferay’s “Expando” back-end services dynamically create and index this new field.

Screen-Shot-2012-12-12-at-10.06.32-AM

Our hook places the Liferay “Expando” data in the Mongo database.  As you can see, Mongo now has a database called “mongo_1”.   Let’s populate the Custom Field, and watch the collection and documents appear.

Screen-Shot-2012-12-12-at-10.07.28-AM
We selected a user in the system and enter their favorite frozen dessert.   The hook grabs data from our user (“company_id”).  The hook uses it to create a collection and document for the user’s data.

Screen-Shot-2012-12-12-at-10.10.36-AM
A query to the “mongo_1” database shows a collection named after our Liferay User class (“com.liferay.portal.model.User”).  That collection has a single document.  That collection holds the primary key and our preferred flavor of a’la mode.

Leveraging MongoDB in content management is exciting and gaining more interest every day.  Developers can dynamically create databases, collections and documents.  They query using javascript syntax.  They can receive full-blown documents in return.  What can Liferay and NoSQL solutions do for you?

Share This