monique

A middleware that utilized rsql-mongodb to parse url queries into mongodb filter and options. Who's monqique? It is not a who, it's just short for Mongo I Query.
Installation
$ npm i @zishone/monique
Usage
const express = require('express');
const { mquery } = require('@zishone/monique');
const MongoClient = require('mongodb').MongoClient;
const app = express();
app.use(mquery());
MongoClient.connect('mongodb://localhost:27017', (err, client) => {
const db = client.db('myDB');
app.get('/get', async (req, res) => {
const { filter, options } = req.mquery;
const cursor = db.collection('myCollection').find(filter, options);
const data = await cursor.toArray();
res.send({ data });
});
app.listen(port, () => {
console.log('Listening at port 3000')
})
});
Queries
- filter
- To filters list of objects.
- Example:
/get?filter=key==value
More at rsql-mongodb
- fields
- To specify which fields of the objects to be returned.
- Example:
/get?fields=key1;key2
- sort
- page
- To skip elements in list of objects based on the given limit.
- Example:
/get?page=1&limit=10
- skip
- To skip elements in list of objects.
- Example:
/get?skip=1
- limit
- To limit elements in list of objects.
- Example:
/get?limit=1
Authors
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.