An easy CRUD operation based on Factory pattern with Mongoose. There are four CRUD operations we can do:

index({mode, where, populateOptions, paginationOptions}) : Fetch all documents with pagination. model - Mongoose model.

- Mongoose model. where - MongoDB filter object.

- MongoDB filter object. populateOptions - Mongoose population object/string.

- Mongoose population object/string. paginationOptions can get three parameters. limit:number - Resource count to show. Default is 10 page:number - Pagination page number. Default is 1. sort:string - MongoDB property sort key. Default is '-createdAt'

can get three parameters.

store({model, data}) - You can create a doc and store it to MongoDB. model - Mongoose model.

- Mongoose model. data - An object of data to store in MongoDB based on Mongoose Schema

show({model, where, populationOptions}) : Fetch a single document via filter key. model - Mongoose model.

- Mongoose model. where - MongoDB filter object.

- MongoDB filter object. populateOptions - Mongoose population object/string.

update({model, where, data}) - updates the first document that matches where . data is the object where you want to update the data. model - Mongoose model.

- Mongoose model. where - MongoDB filter object.

- MongoDB filter object. data - An object of data to update that matches with where filter key(s).

destroy({model, where}) - Deletes the first documents that matches where from the collection. it returns the document that has been deleted. model - Mongoose model.

- Mongoose model. where - MongoDB filter object.