« [Video] Coding Session #11: Sutra CMS Page Action | Main | [Video] Coding Session #12: Reusable Workflow Considerations »
November 19, 2011
[Tip] Connect Servoy to MongoDB
We changed the data structure in the upcoming release of Sutra CMS to key/value pairs for a number of tables. Our aim was to nip runaway table creation in the bud (like what happens in Concrete5 for every new block you install) and potentially add the ability to use a NoSQL data storage for scaling. Sutra CMS is multi-tenant and multi-site and with clustered Servoy servers the RDBMS could conceivably be a limiting factor.
I finally sat down this evening to see if I could get Servoy and MongoDB to talk to each other. Turns out it is stupid easy.
MongoDB download and installation instructions:
http://www.mongodb.org/display/DOCS/Quickstart
Download and put the mongo java driver into Servoy's plugin directory:
https://github.com/mongodb/mongo-java-driver/downloads
Furthermore, MongoDB's data format (BSON) and easy syntax is second nature to a Servoy javascript programmer. It almost has me thinking it might almost be easier to use MongoDB instead of an RDBMS for certain types of programming like meta data driven frameworks, solution model structures, configurations, etc.
I've gone ahead and pasted my inline notes along with the code as I have a couple of outstanding questions to still check on. I want to give the mongodb-rhino jars a testing for the automatic to/from javascript native object conversion and I suspect running all code through the headless client plugin is the proper approach. If you have any ideas, comments appreciated!
Servoy javascript code to test with:
| Posted by David Workman on November 19, 2011 at 02:30 AM in Tips | Permalink
Comments
You might also want to have a look at the MongoDB Connector plugin on ServoyForge: https://www.servoyforge.net/projects/mongodb
The only trouble I have with your approach is that the way you do it (and the way the plugin is also doing it) is to access the MongoDB directly from the client side: potential security troubles here IMHO.
It might help performance to do it this way but realize that you are bypassing the server entirely here... Also your approach would have problems in different environments with strict firewall rules.
This doesn't really fit the Servoy way of accessing the data from the Server only, see my new article https://www.servoyforge.net/projects/articles/wiki/CodeExecution about the Servoy architecture.
The way I would do it is to build a server plugin that would deal with MongoDB interaction on the server side only and the client would then be dealing with the server the way it always do, communicating with the server side plugin. Or as you said have a headless client which sole purpose would be to communicate with the MongoDB server side on behalf of the real client.
Posted by: Servoy Stuff | Nov 19, 2011 3:35:41 PM
Ah k, very cool. Suspicion confirmed and explained so that even I understand it :)
And with a dedicated server plugin vs headless a headless client plugin call -- wouldn't have to worry about dealing with callbacks. Although, having the option to offload to a separate thread for large blob uploading would be good. Maybe combine somehow with the code you put into the file plugin that does file streaming....
Posted by: David Workman | Nov 19, 2011 4:02:50 PM