Guest User

Untitled

a guest
Dec 18th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require('mongoose');
  2.  
  3. var logger = require('./logger');
  4.  
  5. var config = require('../config/config.json');
  6.  
  7. module.exports = {
  8.     connect: function (callback) {
  9.         // Open DB connection to database.
  10.         mongoose.connect(config.database.host, config.database.name);
  11.  
  12.         /*
  13.          * Database checks.
  14.          */
  15.         mongoose.connection.on('error', function (error) {
  16.             logger.info('Connection error: ' + error, {
  17.                 module: 'Db'
  18.             });
  19.  
  20.             callback(error);
  21.         });
  22.  
  23.         mongoose.connection.once('open', function () {
  24.             logger.info('Connection opened.', {
  25.                 module: 'Db'
  26.             });
  27.  
  28.             callback(null);
  29.         });
  30.     }
  31. };
Advertisement
Add Comment
Please, Sign In to add comment