     showHero: false
   ]
 
-  db.collection "pages", (err, collection) ->
-    collection.insert pages,
-      safe: true
-    , (err, result) ->
+  db.collection(collectionName).insert pages,
+    safe: true
+  , (err, result) ->
+    if err
+      console.log "A DB error has occurred"
+    else
+      console.log "The DB had been populated!"
 

#
mongo = require "mongoskin"
BSON = mongo.BSONPure

if process.env.MONGOHQ_URL
  connection_string = process.env.MONGOHQ_URL
else
  connection_string = "mongodb://localhost:27017/nodelove"

db = mongo.db(connection_string + "?auto_reconnect",
  safe: false
)

db.open (err, db) ->
  unless err
    console.log "Connected to 'nodelove' database"
    db.collection "pages", (err, collection) ->
      if err
        populateDB()

#

  catch err
    lookup["slug"] = id

  db.collection(collectionName).findOne lookup, (err, item) ->
    if err
      res.send error: "A DB error has occurred"
    if item
      res.send item
    else
      res.send 404

# Find all pages
exports.findAll = (req, res) ->
  db.collection(collectionName).find().toArray (err, items) ->
    if err
      res.send error: "A DB error has occurred"
    if items
      res.send items
    else
      res.send 404

#
# Render main layout
