We have User
data stored into MongoDB. The client gives a JSONPath query to ask for filtered set of users.
Eg:
$.users[@.salary > 10000]
is a JSONPath query given to retrieve users with salary greater than 10000.
Data:
"users": [ {
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"salary" : 5000,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
},
........
]
}
Whereas, a MongoQuery for the same would be:
db.inventory.find( { salary: { $gt: 10000 } })
We have our Application code in Java which connects to MongoDB.
Is there any way I can run this JSONPath query to MongoDB directly ??
Using Mongo query would mean translating the JSONPath query to MongoQuery which would be cumbersome translating in code. A very brute force method would be to get all Users first on AS (application) and then convert List<Document>
to Json string and then run the JSONPath query.
Any help would be appreciated.