Part1 – Learning & Sharing Series – MongoDB -java

Part1 – Learning & Sharing Series – MongoDB -java

This document is to share some info collected from web and few features i tried out.


The main principle being ‘RDBMS for not all kind of works’. As an article author quotes ‘it has to be NOT ONLY SQL rather than NO to SQL’.

So mainly it is giving up some parts of RDDMS for scaling-speed- flexibility-easiness.

Please read this .Informative.

What I like about the NoSQL crowd.- Good curtain raiser

A very good discussion at

NOSQL storages have 4 formats. 1. Document oriented ( for complex data designs) 2. Key value pairs 3. Column -oriented 4. Graph oriented

My understanding is this.

1. Scalability as TB has become common factor even in home servers

2. Neccessity of easy Real time data mining and reports

3. SQL or schema / relational integrity is not required in many designs and its a overhead.

4. RAM has seen drastic downfall in price .4 GB costs around $100

5. We need ripples once in 2 years like RubyonRails, NOSQL, Virtualization, cloud computing

6. Changing data dimensions because of dynamic business model. This is the real kill .Google Buzz is a new BM for Google.

7. Might be a perfect suit for Data warehouse BII systems where 3NF is the design strategy


One of the best web clipping

“Rather than rows in a table, Mongo stores documents in collections.

Documents are (slightly enhanced) JSON objects, so you can stash much more complex structured data in a single document than you can store in a table row.

Natural data structures: arrays, objects, dictionaries. Data modeling becomes a much more natural process.”

I . Impressed by this link

II More impressed by this link

III Caught in glaze of the NOSQL movement ( though none of the  systems i used in last 5 years scaled more than 3 nodes)  , had a goal of  get  to know about one of the NOSQL DB’s.

Though used memcache and java based in memory libraries in previous projects , this is the first time to try a complete NOSQL persistentDB solution.

Deciding between CouchDB and MongoDB to read about was a tougher decision , though both have good list of production deployments by big firms.Selected MongoDB to read about as couchDB is in alpha

Where Can be used:

There is a clear explanation of use cases given in the Mongodb official website

For more Business cases view the production deployments

esp. this is interesting

[One of the websites cofounder seems to a VC for MongoDB ]

Additional Info about MongoDB

1. Document store model not table-rows-columns. So nested values is possible with eachkeys. Querying will be effective and precise. Uses JSON like Schema.

2. Schemaless- Referential integrity- Joins less.So refactoring and modification is quite easy. For example adding a column to a existing table

3. Currently Win 32/64 ,Linux 32/64, OS-x 32/64 bit, Unix(*NIX only) versions are available

4. Clusterable. Supports Master – Slave, Replica Pairs model.

5. Supports Shard. (Horizontal Partioning)   .Till in Alpha .More details at

6.Claims better performance than Mysql.

MongoDB performed more than 2X better than MySQL

7.Has sets of good features like

  • ”updates-in-place’  using  the Mongo  mondifiers- upsert , $inc .
  • Capped Collections – Fixed size collections having age out based on insert order.Will be handy in logging & Sorting
  • Enhanced Queries

8.Uses JSON for its query and display – BSON binary based JSON for storing documents for efficiency.

9. ACID in supported for only a single document and cannot span multiples. So not for a banking/Financial application

10. For 64 bit machines the data volume is not limited and on 32 Bit system the map file size can be up to a max of 2 GB

11.Online shell  is available at

12. Commercial service providers are currently very limited.

The photon PHP based framework is interesting

13. Drivers are available for java.php ,C#,Ruby,C++,Perl

14 Has import  – from json string formatted document  &  export options – in csv

15. MongoDB does not support transactional locking and the primary reasons said to be to avoid deadlocks , distributed locks and to enhance real time   performance t has other means of support using techniques – ”Update if Current’ & ‘Insert if Not Present’

Simple 3 tries using MongoDB ( Windows) – java

1. General CRUD using java

2. Image persistence and retrieval

3. Large objects saving and retrieving using GridFS

Details about java -MongoDB is available here.

Windows installation is just unzipping the file

[ !Note create a directory \data\db in the same drive where Mongodb resides]

Files in the bin directory

Server Console

General CRUD using java


Insert Result


Search Results


Result after updating



Image persistence and retrieval

Image Retrieval


Native storage of BSON supports only 4 MB it seems and 32 bit it is 2 MB i believe as I got an exception below.

Related documentation and info available at

GridFS Insertion

GridFS – Retrieval

Links that may provide more information


Using JSON –JQuery-java

Part 2 – Learning & Sharing Series

Using JSON –JQuery-java

Good informative links

From Microsoft about JSON

A clean presentation about JSON

Yahoo web services in  JSON

This is a good link to select between different JSON available Libraries in java

Mapping Between -Mapping Between JSON And JavaEntities

Details about getJSON api

Software Used

Json-simple java Library

NetBeans 6.8

JQuery 1.8

Tried the following

1. A simple JSON communication using JQuery and JSP on the server side

2. Using yahoo services with JQuery

A simple JSON communication  using JQuery and JSP on the server side

Made a Simple Server side JSON output using json-simple java Library –

Details about AliceintheWorderland film as JSON output

Used JQuery function getJSON  for parsing the JSON output

The browser output appeared like this

Added an Actors array list to the JSON output

Accessed the URL directly outputs in the browser window like this

The browser output with Actor details

2. Using yahoo services with JQuery

Yahoo web services have  an option to prefer the output format with in JSON/XML

Tried using the yahoo answers web services

In browser the JSON output of yahoo answers service appeared like this – Queried for ipad in yahoo answers

Initially used JQuery get method to test the access and parsing

Once the above step worked tried using the getJSON function

The output appeared in the browser window as follows

— Thanks for your time——-

NOSQL – MongoDB -Info & a short evaluation using its java Driver

With NOSQL movement gaining momentum and big firms like Facebook,Google using it, MongoDB seems to be an important member of the gang along with cassandra,couchDB,Haldoop,
Redis etc.It has notable set of live deployments and has a very organised ( though not much detailed web site)

The attached document has some info i collected from web and some evaluation I did against it using Java.

Download : MongoDB_info_java

Hello world!

Welcome to This is your first post. Edit or delete it and start blogging!