I am Hack Sparrow
Captain of the Internets.

MongoDB with Node.js

MongoDB and Node.js belong to the same league - new age Web technologies that are shaking up the world of Web development. Both of them are revolutionary alternatives to the traditional technologies like MySQL and PHP. Combining Node.js and MongoDB could be the very best option for your next website or app. Now the question is how do you use MongoDB with Node.js? Node.js has a huge collection of excellent module for many many purposes; naturally there ...

Mongoskin Tutorial with Examples

Mongoskin is probably the most developer-friendly MongoDB driver for Node.js at the moment - it is asynchronous and has a clean looking structure. But its docs are not that developer-friendly (the effort is much appreciated though) - no good examples or explanation; probably because English isn't the author's first language. After realizing that the Mongoskin docs may ...

MongoDB – Add Users and Authenticate

Before you add users to databases, you need to add admins to the MongoDB server. If the server is not running with the --auth option, all you have to do is call the db.addUser() function on the admin database. If it is running with the --auth option, you need to select the admin database and identify yourself as a valid admin. [code] > use admin > db.auth('root', 'w00t') ...

MongoDB Pagination – using $slice

Another technique of implementing pagination in MongoDB involves the use of $push and $slice. In this method, we store the documents in an array and use the $slice method to accomplish what skip()-and-limit() does, but without the overhead associated with the skip() method. We will be using a single root document in a collection with two fields: i. an arr ...

MongoDB Pagination – using range queries

This method of MongoDB pagination requires manually setting the _id field in your documents. It uses the min() and max() MongoDB cursor functions to implement the pagination. We'll be learning by examples on a collection named 'companies'. Make sure there are no documents on it. [code] db.companies.remove() [/code] Make sure the _id value starts from 0 and increment ...