node package manager


OData V4 Service modules - MongoDB Connector

Service OData v4 requests from a MongoDB data store.


The OData V4 MongoDB Connector provides functionality to convert the various types of OData segments into MongoDB query objects, that you can execute over a MongoDB database.

Potential usage scenarios

  • Create high speed, standard compliant data sharing APIs

Usage as server - TypeScript

import { createFilter } from 'odata-v4-mongodb'
//example request:  GET /api/products?$filter=category/id eq 5 or color eq 'Red'
app.get("/api/products", (req: Request, res: Response) => {
    const filter = createFilter(req.query.$filter);
    // collection instance from MongoDB Node.JS Driver
    collection.find(filter, function(err, data){
         '@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#products',
         value: data

Usage ES5

var createFilter = require('odata-v4-mongodb').createFilter;
app.get("/api/products", function(req, res) {
    var filter = createFilter(req.query.$filter);
    // collection instance from MongoDB Node.JS Driver
    collection.find(filter, function(err, data){
         '@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#products',
         value: data

Supported OData segments

For now $filter, $select, $skip and $top

Support for $expand is next.

Supported $filter expressions

The OData v4 Parser layer supports 100% of the specification. The Connector is supporting basic MongoDB queries.

We are into creating a comprehensive feature availability chart for V1 release

√ expression NullValue eq null
√ expression TrueValue eq true
√ expression FalseValue eq false
√ expression IntegerValue lt -128
√ expression DecimalValue eq 34.95
√ expression StringValue eq 'Say Hello,then go'
√ expression DurationValue eq duration'P12DT23H59M59.999999999999S'
√ expression DateValue eq 2012-12-03
√ expression DateTimeOffsetValue eq 2012-12-03T07:16:23Z
√ expression GuidValue eq 01234567-89ab-cdef-0123-456789abcdef
√ expression Int64Value eq 0
√ expression A eq INF
√ expression A eq 0.31415926535897931e1
√ expression A ne 1
√ expression A gt 2
√ expression A ge 3
√ expression A lt 2
√ expression A le 2
√ expression: A/b eq 1
√ expression (A/b eq 2) or (B/c lt 4) and ((E gt 5) or (E lt -1))