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: ...

Get RESTful Web API Design with Node.js - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.