Building with MongoDB – NodeJS – Robomongo



Getting Started…

with MongoDB, NodeJS, Robomongo

Do you want to learn more about NoSQL databases. The following is a two-part series on building fast apps with MongoDB, NodeJS and Robomongo (great MongoDB tools).  The first part is about getting and installing the tools along with a simple primer on how to build a simple mongodb database.  In the next post, we’ll explore building a twitter stream and sending tweets into a local mongodb database.

Just for clarity, If you don’t know about MongoDB  and you work in Big Data, Business Intelligence or Analytics you should probably learn.  What is MongoDB – MongoDB is an open source, document-oriented database designed with both scalability and developer agility in mind. Instead of storing your data in tables and rows as you would with a relational database, in MongoDB you store JSON-like  [JavaScript Object Notation ] documents with dynamic schemas.

Finally, We going to learn some basic analytics for MongoDB using Map-Reduce and JavaScript.  Wait, Can we use SQL too. Yes, You can and in later post I’ll show you have to integrate your data in Cassandra, Hadoop, Hive, Spark. If you have a well architected MongoDB cluster that is properly configured – you should get solid performance. Also, Hadoop (Hive – Spark) plays well with JSON data for large scale – fast analytics.

MongoDB Installation

Mongo does a great job with documentation. This is the “Link” to install MongoDB.  Here is more information on installing MongoDB on Windows and Linux.

The following is a short example using Brew with OSX (Soon to be MACOS).

host:bin kyanyoga$ brew update
Already up-to-date.  [you want to see this after you've done you brew installation].

host:bin kyanyoga$ brew install mongo  [ That's it. ] 
... [ After you should see something like this. ]
==> Options
	Compile using installed boost, not the version shipped with mongodb
	Compile with SASL support
	Build without openssl support
==> Caveats
To have launchd start mongodb now and restart at login:
  brew services start mongodb
Or, if you don't want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf

[ Go Ahead and start the server in a Terminal Window ].
host:bin kyanyoga$ mongod --config /usr/local/etc/mongod.conf
[ open a second terminal window and run the mongo command line].
host:bin kyanyoga$ mongo
MongoDB shell version: 3.2.6
connecting to: test
> show databases  [ Issue this command : make sure you can see a database ].
aggregation_example  0.078GB
demo                 0.078GB
local                0.078GB
test_database        0.078GB

There is allot more to MongoDB – However, This will get you the basics going for Development.  Setting up a production clusters is a non-trivial task that requires a MongoDB expert to do it right. If you’re having problems with your Cluster; We can help re-configure your installation and optimize performance [ on-premise & AWS Cloud ]. Please Email Us

NodeJS Installation

First, The download and installation “Link” for NodeJS.  Find your correct operating system, Download the package and follow the instructions. For Windows and Mac OSX, its fairly straight forward.  When installing on different versions of Linux, you may have to install Node from source. This is  bit trickier and requires you to have the development tools installed in your flavor of Linux as well.  So, Please read the instructions – For this Getting Started, I recommend Windows or OSX.

Also, You’ll want to familiarize yourself with the NPM Node Package Manager. This allow you to install various packages you will need while developing and/or following this getting started.   – Link Here – .

Check your Installation… If you’re a JavaScript programming – Go ahead and have some fun.

host:bin kyanyoga$ node -v

[ run a few java script commands - don't worry about the undefined for now. ]
host:bin kyanyoga$node
> var name = { firstname : "Gus", lastname : "Segura" };
> console.log(name);
{ firstname: 'Gus', lastname: 'Segura' }
> console.log(name.firstname);
> Ctrl-D ( To Exit)
- OR - 
vi test.js [ Enter the following code - use your name :) ]
var name  =  { firstname : "Gus", lastname : "Segura" };
Then... [ run the code with node ]
host:bin kyanyoga$node test.js
host:bin kyanyoga$

Robomongo Installation

So, You will need an editor when we get to the NodeJS part of the coding. However, For connecting to MongoDB, I’ve been using this great tool for years;  Robomongo : Native Mongo Management – Admin tool for Mac OSX.   Follow the link, download and install the Tool. The first thing you’ll want to do is configure a connection to your local mongodb.  You can add a name, use your localhost for local installation and the port address you used to start MongoDB.

MongoDB Connections

Then.. Right Click (on the connection name you created for your local connection) ->  Left Click Create a Database. Enter a Database Name like: streamworld.  Then in the following screen shot you can Create a Collection and Insert a few records.


Enter the text. You’ll notice the tool will generate auto-finish like tool tips. Then hight-light the text, Then press the Green Execution Triangle, Observe the results.  Congrats! You just created your first MongoDB document database with a collection of documents.  Try Right clicking on the database, collections, functions, users, indexes…etc.  Feel free to “Play”.  Try a few commands.  Just start typing “db. ” into the command window.  Like : db.wally.find() .   Have Fun!

Final Thoughts – Next Posts…

There are plenty of demo’s and walkthroughs out there in the MongoDB documentation and NodeJS.  Make sure to shut things down when your done.  In the my next post, I’ll show you how to stream twitter into MongoDB and then do a bit of analytics with Map-Reduce and JavaScript.  We needed NodeJS because, I have a very simple streamer that will push ALLOT of data into MongoDB quickly – So we’ll have data to test with quickly.


Please Contact US or Subscribe to our Blog if you found this interesting or would like more information.

Subscribe : Blueskymetrics Blog

* indicates required,  Managed By Mail-chimp – Please check your Spam Folder and Confirm Subscription.