moncrud-leo
using MongoDB with Mongoose and Express
moncrud-leo package helps creating a model with Ajax Create, Read, Update, Delete structure. Because in many scenarios, I needed same types of AJAX calls to manipulate and retrieve data, and I got tired of writing tons of code for it, I have descieded to credate a package for it.
It takes care of creating the model, creating all standard data calls, feeding data to DataTables with server-side search, sorting and pagination, and, of course, custom actions.
It is very easy to implement and set up this engine!
https://github.com/lbarsukov/moncrud-leo
tagsMongoDB Mongoose Express Crud Create Update Delete Read DataTables Ajax Search Sort
Basics
Initialize moncrud-leo
var mc = ; mc;
More Options and Details
var mc = ;// this depends on express, give the initializer the [app] elementmc;
Using moncrud
// require moncrudvar mc = ;// create a modelvar users = mc;// After the model is created, you can initate CRUD// basic CRUD initializer:users;// users.crud() function initiates HTTP\post calls: '/api/users/' [find, find-one, add, update, remove]// you can also customoze the controllerusers;
This produces URL's to work with the data
- /api/users/find-one
- /api/users/find
- /api/users/add
- /api/users/update
- /api/users/remove
All methods are 'post' methods, because they can all send data to use 'find-one', you feed parameters, such as '_id' as an AJAX data request jQuery action looks like this:
$;
This method becomes the the one you can use for any method. Of course, if you are adding the data, you would need to specify all the properties.
## Implementing DataTables AJAX request, pagination #### Feature is emplemented at root level, off by default The DataTables client-side initialization will work the same way you would normally do it. Please look at this example. ```html
Client-side JavaScript
You must include jquery.js, datatables.js please go to https://www.datatables.net/examples/data_sources/server_side.html for more details.
The example on the provided link is focusing on php, so it's not very relevent. This controller sends data as objects, not arrays; thus the "columns" element will be required.
;
// Server-side script// this initates a model, just like you see abovemc;