Have ideas to improve npm?Join in the discussion! »

    seal-odata-mongo

    0.0.8 • Public • Published

    seal-odata-mongo

    CircleCI AppVeyor

    seal-odata-mongo is a middleware that translates OData to MongoDB queries. OData Version 2.0 URI conventions are supported.

    Installation

    $ npm install seal-odata-mongo

    Quick start

    First you need to add a reference to seal-odata-mongo within your application.

    const odataMongo = require('seal-odata-mongo');

    Then you can enable Express routes to handle incoming OData queries. For that, add the middleware to the appropriate route. Within the route you then can access the req.mongo.query and req.mongo.queryOptions objects that contain the query and the query options for MongoDB.

    app.get('/data', odataMongo(), (req, res) => {
      db.collection('...').find(req.mongo.query, req.mongo.queryOptions).toArray((err, docs) => {
        // ...
      });
    });

    In case the client sends an invalid OData expression, the middleware responds with a 400 status code.

    supported OData keys

    • $filter
    • $top - limit the result to N elements
    • $skip - skip N elements of the query
    • $select
    • $inlinecount - see implementation example in seal-rest to retrieve count and the result
    • $orderby

    Running the build

    To build this module use roboter.

    $ bot

    Keywords

    none

    Install

    npm i seal-odata-mongo

    DownloadsWeekly Downloads

    1

    Version

    0.0.8

    License

    MIT

    Last publish

    Collaborators

    • avatar