Creating a user-defined model around a Mongoose model
After seeing how a model works, it is time to create a user-defined module, called conctactdataservice, which wraps all CRUD operations for a contact. Since we intend to use that module in a RESTful web application, it seems logical to leave the schema definition and the model creation outside the module and have them provided as arguments of each module function. For now, the module will provide an implementation for each CRUD function, starting with a remove()
function. It looks up a contact based on its primary contact number and deletes it from the database, if it exists:
exports.remove = function (model, _primarycontactnumber, response) { console.log('Deleting contact with primary number: ' + _primarycontactnumber); model.findOne({primarycontactnumber: _primarycontactnumber}, function(error, data) { if (error) { console.log(error); if (response != null) { response...