Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sammoore/mongoose-router
An HTTP Router for your Mongoose Model.
https://github.com/sammoore/mongoose-router
Last synced: about 1 month ago
JSON representation
An HTTP Router for your Mongoose Model.
- Host: GitHub
- URL: https://github.com/sammoore/mongoose-router
- Owner: sammoore
- License: isc
- Created: 2017-11-06T16:39:56.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T23:56:12.000Z (9 months ago)
- Last Synced: 2024-10-28T16:54:33.094Z (3 months ago)
- Language: JavaScript
- Size: 36.1 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoose-express-router
> Create Express 4 router and middleware from Mongoose 4 model.
## Usage
```javascript
var express = require('express');
var mongoose = require('mongoose');
var router = require('mongoose-express-router');var db = mongoose.createConnection('mongodb://localhost/test');
var schema = mongoose.Schema({ name: 'string' });
var User = mongoose.model('User', schema);var app = express();
app.use('/users', router(User));app.listen(3000);
```The underlying [mongoose-controller][mongoose-controller] used by each middleware
is available, as well as the middleware functions themselves:```javascript
router(User).middleware
router(User).controller
```### Queries
The following query parameters are recognized:
- `skip` or `offset`
- `limit`
- `sort`
- `select`
- `populate`
- `where` \*> \*: where depends on the availability of nested query string parameters.
In addition, any `req.params` will be assigned as where parameters. This is useful
if nested query parameters are not available, as multiple routes can point to one
instance of a router. For example:```javascript
var app = express();
var r = router(Model);app.use('/model/skip/:skip', r);
app.use('/model', r);
```### Body parsing
You must provide your own body parsing middleware. A `req.body` object must be
available for the post/create middleware to work.### Builtin middleware
_Incomplete_
[mongoose-controller]: https://github.com/samtheprogram/mongoose-controller