I am using
app.get('/', function(req, res){
var listData = function(err, collection) {
collection.find().toArray(function(err, results) {
res.render('index.html', { layout : false , 'title' : 'Monode-crud', 'results' : results });
});
}
var Client = new Db('monode-crud', new Server('127.0.0.1', 27017, {}));
Client.open(function(err, pClient) {
Client.collection('users', listData);
//Client.close();
});
})
This method to get records from mongoDB and showing in a html. I am using Express, hbs as view engine.
I need a common method where I can pass collection name or mongo query, it should return the collection as result. In the main page i can process the collection. Just like splitting data logic in separate classes in C#. How to achieve this?