I recently began working with Node and MongoDB for a small personal project, largely just to learn the technologies. One thing that is fairly simple but that I found far from obvious and lacking in concrete examples was how to populate the part of my database that used referenced collections from the sample JSON data I was starting with. This post attempts to fill that gap using the following code snippets, which are heavily commented inline. You will notice I am using the awesome Mongoose library which makes working with MongoDB very easy.
http.createServer( app ).listen( app.get( 'port' ), function() {
mongoose.connect( 'mongodb://localhost/{YOUR_DB_NAME}' );
var db = mongoose.connection;