home‎ > ‎Programming‎ > ‎Comparing NoSQL Data Stores‎ > ‎


A zipped version of my MongoDB project is attached below.

I downloaded version 2.4.6 (latest current) - but the 32-bit version.

As usual, I set MONGODB_HOME to the root folder and added %MONGODB_HOME%/bin to my path

Server setup

Documentation on MongoDB is pretty good on installation and the use of the Java driver - to help get you off the ground quickly.

Having set up the environment variables as above, I executed this on my C: drive (on a DOC window)
md data md data\db

This created the database folders as follows

In order to start the server, run


on a DOS shell (as long as you have set the MONGODB_HOME variable and added the bin folder to your path as explained above)


You should be able to execute the connectivity tests once you have set the server up (which demonstrates database creation, testConnectivity, and deletion, testDropDB)

You can now launch the mongo.exe command on another DOS shell. If you execute

show dbs

you might see something like this (depending on what you have executed previously)

After you have run the tests, you should be able to see the collections

Data Population

I decided to store serialized objects of Trade and Market data into the document (collection). Perhaps this is not the way MongoDB was best designed for use, but it kept my use case consistent across the systems.

Binaries are stored in BSON format and I must admit I am not a fan. The method insertMarketData in MarketDataCreatorTest shows how this is done


       ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectMapper mapper = new ObjectMapper(new BsonFactory());
        mapper.writeValue(baos, marketData);
        dbObj.put("marketData", baos.toByteArray());

Querying and Filtering

MongoDB requires the parameters involved in a query to be exposed as attributes in the document. For example, optionType was exposed as a Boolean attribute for TradeData (see insertTradeData in TradeDataCreatorTest)

    private WriteResult insertTradeData(DBCollection dbCol, EquityTradeData equityTradeData) throws IOException {
        BasicDBObject dbObj = new BasicDBObject();
        dbObj.put("optionType", equityTradeData.isCall());

When executing testPricing (see PricingTest.java), the query is built up as follows

       BasicDBObject query = new BasicDBObject("optionType", false);
        DBCursor cursor = tdCol.find(query);

The resulting cursor should contain the appropriate filtered document set

Raj Subramani,
13 Nov 2013, 10:04