JSONPath query on MongoDB? JSONPath query on MongoDB? json json

JSONPath query on MongoDB?


This cannot be done out of the box at this stage - see this open request: https://jira.mongodb.org/browse/SERVER-736

I would personally recommend you to go with some kind of translation approach - it's the only viable option I see apart from the brute-force client side evaluation which simply doesn't scale (but would probably be very ok for small data sets). Plus, the code you need to translate your queries can be nicely unit tested so it should be a reasonably safe bet.

Here are some ideas for where to source/base the required translation code from/on.

Regex and parsing based (specifically for MongoDB): https://github.com/gabrielelana/mongodb-shell-extensions/blob/master/src/jsonpath.js

Alternatively, this could perhaps be used to parse JSONPath strings into an object model which you could then translate into MongoDB queries: https://github.com/json-path/JsonPath