     count = cursor.limitValue || count if count isnt 0
     return done err, 0, count if err or count is 0
     next 0, count
-  
+
+#
+# Get matching documents from collection
+#
+Database.prototype.getDocuments = (col, query, fields, options, cb) ->
+  col.find(query,fields,options).toArray cb
+
+#
+# Get document for ID
+#
+Database.prototype.getDocument = (col, id) ->
+  col.findOne _id: id, cb
+
+# Export database
+module.exports = Database
+

"use strict"

MongoClient = require('mongodb').MongoClient
format = require('util').format

#
# Connect to database
#
# @param {@code String} collection - collection name
# @param {@code Function} cb - callback function (err, db)
#
# github.com/mongodb/node-mongodb-native/blob/master/docs/articles/MongoClient.md
#
exports.connect = (custom_uri, cb) ->
  switch process.env['MODE']
    when "production" then uri = process.env['MONGO_PROD_URI']
    when "stage" then uri = process.env['MONGO_STAGE_URI']
    when "development" then uri = process.env['MONGO_DEV_URI']
    else uri = "mongodb://localhost:27017/ntb_test"

  uri = custom_uri if custom_uri isnt null

  MongoClient.connect uri, (err, db) ->
    cb err, db

#
# Process documents syncronously

# @todo add counter
# @todo add success, fail calbacks?
#
Database.prototype.each = (cursor, fn, done) ->
  next = (i, count) ->
    return done null, --i, count if i is count
    cursor.nextObject (err, doc) ->
