@sealsystems/odata-mongo
v1.0.0
Published
@sealsystems/odata-mongo is a middleware that translates OData to MongoDB queries.
Downloads
23
Readme
@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 tonone
the response is the result array. If set toallpages
the response is an object withresults
as the result array andtotalCount
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:
.