Can we use geo queries for mongodb in rest api's


#1

hi

is it possible to utilize geo spatial queries operator of mongodb using rest api in dreamfactory
for e,g
something along the lines of
db.zips.find( { ‘loc’: {$near : [ 47.6, 117.45] } } ).limit(3)

thanks
any curl example will be really helpful


#2

It doesn’t look like anyone in the community has tried what you’re trying yet, @ikyaqoob. But please do come back and post your solution once you’re done!


#3

Hi Jeff
DreamFactory is really such an amazing MBAAS
i can access MongoDB using standards swagger generated api’s using SQL type queries
and if I have to use the operators which are native to MongoDB only

guess what , even they can be easily accessed
the main reference that was really helpful was once again

in js api it looks like
window.df.apis.localmongo.getRecordsByPost({table_name: “geotest”,body: {“filter”:{ “loc”: { “$near” : [ 47.6, 117.45] } }

    },"X-HTTP-METHOD":"GET"},function(response){
     meme=response;
}, crudError
);

///////////////////////////////
due to the language agnostic design of dreamfactory , i can test my logic using CURL then using live api’s and finally adapt it using the api so it’s a three way treat

thanks once again guys for putting such a fantastic product


#4

Just wondering how you actually filtered using geo queries. When i try to filter using geo query’s i get:

Failed to filter records from ‘mycollection’.\nMongoCollection::find(): expects parameter 1 to be an array or object, string given

I suspect i’m not passing the filter correctly. This is what i’m passing in the filter input box:

{“loc”:{$near: {$geometry: {type: “Point” ,coordinates: [ 43.89…,-78.97… ]},$maxDistance: 3000,$minDistance: 100}}}

loc is the name of the field that i’m trying to filter on. When i run this in the Mongo Command line i get appropriate results. But i can’t seem to figure out how to do it through DreamFactory. The blog post that you suggested is a little out of date. How can i call the getRecordsByPost() request? Is that a query paramater?

Thanks in advance,

Sean


#5

After some further investigation it looks like i was missing quotes. Here’s the working filtered data that i used in the text input of the dreamfactory api docs section:

{“loc”:{"$near": {"$geometry": {“type”: “Point” ,“coordinates”: [ 43.89,-78.97 ]},"$maxDistance": 3000,"$minDistance": 100}}}

This post should help anyone with a similar issue:
https://github.com/dreamfactorysoftware/dsp-core/wiki/Database-Retrieving-Records#get-post-filter