@sealsystems/odata-mongo

1.0.0 • Public • Published

@sealsystems/odata-mongo

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

Installation

npm install @sealsystems/odata-mongo

Quick start

First you need to add a reference to @sealsystems/odata-mongo within your application.

const odataMongo = require('@sealsystems/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 - list of result properties
  • $top - limit the result list to N
  • $select - list of result properties
  • $inlinecount - if missing or set to none the response is the result array. If set to allpages the response is an object with results as the result array and totalCount with the total count of entries found for this query
  • $orderby - sort by a field

Running the build

Builds and releases are triggered on GitHub by dependabot if commit comment starts with fix: or feat:.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

Package Sidebar

Install

npm i @sealsystems/odata-mongo

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

5.12 kB

Total Files

4

Last publish

Collaborators

  • seal-mt
  • michaelscherer-seal
  • comgit
  • gel