Can not read property 'collection' of undefined

0

Error:

TypeError: Cannot read property 'collection' of undefined
    at Object.findAll (/Users/filipealves/node/crud/db.js:7:17)
    at /Users/filipealves/node/crud/routes/index.js:6:13
    at Layer.handle [as handle_request] (/Users/filipealves/node/crud/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/filipealves/node/crud/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/filipealves/node/crud/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/filipealves/node/crud/node_modules/express/lib/router/layer.js:95:5)
    at /Users/filipealves/node/crud/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/Users/filipealves/node/crud/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/filipealves/node/crud/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/Users/filipealves/node/crud/node_modules/express/lib/router/index.js:174:3)

Code:

const mongoClient = require('mongodb').MongoClient
mongoClient.connect('mongodb:/localhost:27017/workshop')
.then(conn => global.conn = conn.db('workshop'))
.catch(err => console.log(err));

function findAll(callback) {
    global.conn.collection('customers').find({}).toArray(callback);
};

module.exports = {findAll};
    
asked by anonymous 23.08.2018 / 11:07

0 answers