@sealsystems/odata-mongo is a middleware that translates OData to MongoDB queries.

Usage no npm install needed!

<script type="module">
  import sealsystemsOdataMongo from 'https://cdn.skypack.dev/@sealsystems/odata-mongo';



CircleCI AppVeyor

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


$ 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

To build this module use roboter.

$ bot