List of Known Scalable Architecture Templates

This weekend came across a nice blog by Srinath which I found quite useful and highly recommend for the people interested in developing Web Scale Architecture like Google and Facebook.

http://srinathsview.blogspot.com/2011/10/list-of-known-scalable-architecture.html

Node.JS & MongoDB – Looping through Collection using core MongoDB library

As we all know that MongoDB is very good companion to Node.JS because of the linkage with JSON which is common to both the platforms. JSON is an integral part of Node.JS as it is JavaScript and MongoDB stores data in Binary JSON format.

Now the question is how to perform some simple operations like looping through the objects in collection. This article assumes that you have already installed the core MongoDB library using Node Package Manager (NPM).

sudo npm install mongodb

Now the very first step is to declare the variables pointing to the ‘MyDB’ database in MongoDB:

===================================================================================

// MongoDB Connection
var Db = require('mongodb').Db,
    Connection = require('mongodb').Connection,
    Server = require('mongodb').Server,
    BSON = require('mongodb').BSONNative;

var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;

var db = new Db('MyDB', new Server(host, port, {}), {native_parser:true});

===================================================================================

Now lets assume there is a collection called Customers in our MyDB database and we need to loop through it.

===================================================================================

db.open(function(err, db) {
    db.collection('Customers', function(err, collection) {
        collection.find(function(err, cursor) {
            cursor.each(function(err, customer) {
                if(customer != null){
                    console.log('First Name: ' + customer.firstName);
                    console.log('Last Name: ' + customer.lastName);
                }
                else{
                    db.close();
                }
            });
        });
    });
});

===================================================================================

Hope you will find this useful.

Till then Happy Coding!!!

Building for Future: Native App vs Web App – jQuery Mobile, Sencha Touch libraries will be helpful to Developers

Sometime back I posted a blog ‘HTML5, AJAX, JavaScript, JavaScript Libraries (e.g. jQuery) – Future of Client Programming’ stating my thoughts on what will be future of client application development where developers doesn’t need to bother about multiple platforms.

In that blog I talked about the client libraries like jQuery, YUI etc… however one thing we need to note here is the UI has to be optimized for two types of devices traditional desktop and laptop where users interact with the application using mouse an other type of devices like smart phones (IPhone, Android, Windows Phone 7) and tablets (IPad, HoneyComb etc.)  where users interact with the device using touch interface.

For the smartphones and tablets there are already libraries released which supports these touch based devices.

jQuery Mobile:

http://jquerymobile.com/demos/1.0b1/

Sencha Touch:

http://www.sencha.com/products/touch/demos/

I would highly recommend going through the demos which provides good ideas on what points should be considered during building for mobile / tablet optimized web applications.

MongoDB on Ubuntu – REST is not enabled. use –rest to turn on Error

MongoDB is really becoming a very popular NoSQL data store. This is specially due to its features and also due to its adoption in many popular applications like craiglist, foursquare, bit.ly, intuit, sourceforge etc. the list goes on. The complete list can be found here http://www.mongodb.org/display/DOCS/Production+Deployments.

Installing MongoDB on Ubuntu is fairly straightforward. Just issue the command:

$ sudo apt-get install mongodb

Once installed it basically runs on the native driver port 27017. It also exposes a http server on port 28017 which can be accessed via browser. Now when you try to browse the URL http://127.0.0.1:28017 it displays the landing page for MongoDB. Now there is a link to list all the commands:

image

Clicking on this we might get this error:

image

This is because the http server on port 28017 communicates with the MongoDB server on port 27017 via REST interface which is not enabled by default.

To enable this we need to make change to /etc/mongodb.conf file. This is a read only file so we need to open with sudo.

$ sudo vim /etc/mongodb.conf

image

As mentioned in the above screenshot we can add the command for enabling the rest.

Once this is done we need to restart the MongoDB server.

$ sudo restart mongodb

Now we can browse the URL and we should be able to see all the commands.

image

Follow

Get every new post delivered to your Inbox.