1.0.6 • Published 6 years ago

mrq-client-query v1.0.6

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

mrq-client-query

A mongoose middleware extending the behavior of mongoose-rest-query, providing more flexibility by allowing querying to be done at client.


Motivation

  • Less code @ server for queries that requires Query Operators
    • Less middlewares
    • Less routes
    • Less controllers

What it does

  • handleJSON(req, res, next): Converts each value in req.query to JSON.

  • setModel(models): Set models variable to models (format: {modelName: model}) for customAPI to use.

  • customAPI(req, res): Allow querying to be done from Client.


Set up

var mrqClient = require('mrq-client-query'),
    app = require('express')();

mrqClient.setModel(model);

app.use(mrqClient.handleJSON);
app.use('/api/custom', mrqClient.customAPI);

Use

In addition to mongoose-rest-query, the following query operators can be used:

  • $eq
  • $ne
  • $exists
  • $regex
  • $text

(not all have been tested)

mrq already allows:

  • $gte
  • $gt
  • $lte
  • $lt
  • $ne (Bug in mrq, 'null' was being passed by Mongoose to MongoDB as string)
  • $in
  • $nin

Limitations

  • Query operators which uses arrays cannot be used

    E.g:

    var query = {
                type: TYPE.clothing,
                $or:
                    [
                        {
                            hasDesignations: false
    
                        },
                        {
                            parentDesignation: { $ne: null }
                        }
                    ]
    }

    mongoose-rest-query converts the array into:

    { '$and': [ 
            { $or: { hasDesignations: false }, 
            { $or: { parentDesignation: { $ne: null } }
        ]
    }

    ERROR: $or needs array

    To pass array, use JSON.stringify


Version of mongoose-rest-query tested: 0.1.6

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago