I am Hack Sparrow
Captain of the Internets.

Archive for November, 2011

Form Handling / Processing in Express.js

Depending on where you come from, you either call it form processing or form handling, but they mean the same thing - doing stuff to things submitted through an HTML form. In this tutorial I'll show you how to handle all aspects of form processing in Express.js. Express.js is the most popular web development framework as of this writing. There are two major aspects to HTML forms: i. GET requests, ii. POST requests. Let's see how we deal with them in Express. ...

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 ...

MongoDB Pagination – using skip()

Curious how pagination might be implemented in MongoDB? Let's have a data set to play around with so that we can learn by examples. Create a collection named companies and add some documents on it. [code] db.companies.insert({name:'Google'}) db.companies.insert({name:'Facebook'}) db.companies.insert({name:'Apple'}) db.companies.insert({name:'Microsoft'}) db.companies.insert({name:'Oracle'}) db.companies.insert ...

Express.js Jade Partials – How to use them

Partials are mini views that can be rendered in a HTTP response. They are mainly used for modularizing the view of an HTTP response. Since Jade is the default HTML template engine, this post explains what partials are in Express assuming we are talking about Jade partials for Express.js. Partials are regular Jade templates that caters to specific part of a larger view. For example, if you want to break up the view of a page of vi ...