Files
yeoman-angular-express-plus/server/db/example.js
2013-05-14 22:56:13 +01:00

30 lines
812 B
JavaScript

'use strict';
var appConfig = require( '../../app-config.json' ),
db = require( '../db' ).db( appConfig.database.name );
// Example route
module.exports = function( req, res ) {
console.log( 'Accessing database ' + db.databaseName );
db.collection( appConfig.database.collection, function( err, collection ) {
if ( err ) {
console.log( 'Error accessing collection' );
console.log( err );
return err;
}
// Find all items and return them
collection.find().toArray( function( err, items ) {
if ( err ) {
console.log( 'Error finding items in collection' );
console.log( err );
return err;
}
res.send( items );
} );
} );
};