Code Monkey home page Code Monkey logo

odata-v4-mongodb's Introduction

OData V4 Service modules - MongoDB Connector

Service OData v4 requests from a MongoDB data store.

Synopsis

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){
        res.json({
        	'@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){
        res.json({
        	'@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 5.1.1.6.1: NullValue eq null
√ expression 5.1.1.6.1: TrueValue eq true
√ expression 5.1.1.6.1: FalseValue eq false
√ expression 5.1.1.6.1: IntegerValue lt -128
√ expression 5.1.1.6.1: DecimalValue eq 34.95
√ expression 5.1.1.6.1: StringValue eq 'Say Hello,then go'
√ expression 5.1.1.6.1: DurationValue eq duration'P12DT23H59M59.999999999999S'
√ expression 5.1.1.6.1: DateValue eq 2012-12-03
√ expression 5.1.1.6.1: DateTimeOffsetValue eq 2012-12-03T07:16:23Z
√ expression 5.1.1.6.1: GuidValue eq 01234567-89ab-cdef-0123-456789abcdef
√ expression 5.1.1.6.1: Int64Value eq 0
√ expression 5.1.1.6.1: A eq INF
√ expression 5.1.1.6.1: A eq 0.31415926535897931e1
√ expression 5.1.1.1.2: A ne 1
√ expression 5.1.1.1.3: A gt 2
√ expression 5.1.1.1.4: A ge 3
√ expression 5.1.1.1.5: A lt 2
√ expression 5.1.1.1.6: A le 2
√ expression: A/b eq 1
√ expression 5.1.1.3: (A/b eq 2) or (B/c lt 4) and ((E gt 5) or (E lt -1))

odata-v4-mongodb's People

Contributors

aaghevli avatar borzav avatar lazarv avatar peteraronzentai avatar slajher avatar tisos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odata-v4-mongodb's Issues

Regex special characters are not escaped

The second argument of a contains, endswith or startswith method call should be regex escaped before being used to create a regex. Otherwise, the method call contains(A, '.') results in the regex /./gi, which matches any one character instead of just ..

Orbit

I’ve spent five years building a project that I’d love to put on the npm name orbit.

If you could chat with me, I’d love to show you it and make a proposal to acquire it from you.

[email protected]

The repository and package are missing a license file

I understand from looking at the package.json file that the intended license is MIT. However, based on the the GitHub documentation, the repository and package need a proper LICENSE.md file in order for other users to fork, modify, and use the source code in unambiguous legality.

I will create a PR with a proposed license file to simplify the resolution of this issue. I have created similar issues for this repositories' dependencies (odata-v4-literal and odata-v4-parser).

Because the latest commit is from Aug 22, 2017, I doubt the repository is still being maintained. This makes this addition all the more important so that the work isn't simply lost.

Support all / any for arrays

The parser contains this information, but it is not implemented by the mongodb filter creation.

I looked at the code, but am not sure how it could best be implemented.

Exception while using special characters in expression value

Hi,
I am getting exception while using '/' in expression value. for example:

var query = createQuery("$filter=status ne 'FIXED/RESOLVED'");

Error: Unexpected character at 14$filter=status ne 'FIXED/RESOLVED'
at D:\workspace\AmeriGas\API-Server\api-server\node_modules\odata-v4-parser\lib\parser.js:25:19
at Object.query (D:\workspace\AmeriGas\API-Server\api-server\node_modules\odata-v4-parser\lib\parser.js:45:93)
at createQuery (D:\workspace\AmeriGas\API-Server\api-server\node_modules\odata-v4-mongodb\lib\index.js:6:66)

Thanks

Filtering and ordering at the same time fails the sorting

If I send a $filter=contains(Name,'c')&$orderby=UnitPrice request, the visitor looks like this:

{
  query: { Name: /c/gi },
  sort: { NameUnitPrice: 1 },
  ...
}

And if I send a $filter=contains(Name,'c')&$orderby=Name request, the visitor is:

{
  query: { Name: /c/gi },
  sort: { NameName: 1 },
  ...
}

It works fine if I skip the $filter or the $orderby: $orderby=UnitPrice or $filter=contains(Name,'c')

invalid createQuery result if used or, contains and eq

Hi,

function createQuery produces invalid result if supplied with following query:
filter=contains(Name,'be') or Name eq 'Produce'

Input:
http://odata-v4-demo.jaystack.net/api/Categories?$filter=contains(Name,'be') or Name eq 'Produce'

Output:
{
"@odata.context": "http://odata-v4-demo.jaystack.net/api/$metadata#Categories",
"value": [
{
"@odata.id": "http://odata-v4-demo.jaystack.net/api/Categories('578f2baa12eaebabec4af289')",
"@odata.editLink": "http://odata-v4-demo.jaystack.net/api/Categories('578f2baa12eaebabec4af289')",
"_id": "578f2baa12eaebabec4af289",
"Description": "Soft drinks",
"Name": "Beverages"
}
]
}

i.e. one element is missing ('Produce' category)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.