Postman (and python eve) providing different results to same query when done in mongodb -
i'm developing light weight api using python eve, access mongodb database. each document in database has geom field , there 2d sphere index on field.
when run query in mongo works , quickly
db.api.aggregate({"$geonear": {"near": {"type": "point", "coordinates": [-1.11, 51.69]}, "distancefield": "distance", "maxdistance": 100, "num": 2, "spherical": "true"}}).pretty() but when run in postman returns , ignores query
http://localhost:8090/data?aggregate={"$geonear": {"near": {"type": "point", "coordinates": [-1.11, 51.69]}, "distancefield": "distance", "maxdistance": 100,"num": 2,"spherical": "true"}} i have basic schema set in eve, partly works. it, returns _id not distance field created part of query. although i'm running on assumption work once have syntax postman correct.
api_shema = {'_id': {'type': 'string'}, 'distance': {'type': 'string'} } i have item set up
line_info_item = {'item_title': 'line_info', 'resource_methods': ['get'], 'schema': api_shema, 'datasource': { 'source': 'api', 'filter': {'_type': 'line'} } } finally following domain added
domain = {'line_info': line_info_item} any postman query, or if spot errors in rest, appreciated.
edit:
i set pipeline on endpoint per neil's answer below it's still ignoring query , returning all.
domain = {'line_info': line_info_item, 'aggregation': { 'pipeline': [{ "$geonear": { "near": { "type": "point", "coordinates": ["$coords"] }, "distancefield": "distance", "maxdistance": "$maxdist", "num": 10, "spherical": "true" } }] } } the postman query url is
http://localhost:8090/data?aggregate={"$maxdist":500, "$coords":[-1.477307, 50.931700]} edit
sort of working, although ignoring schema... guess thats different question.
moved aggregation pipeline item , removed square brackets around "$coords"
river_relate_item = {'item_title': 'line_info_item', 'resource_methods': ['get'], 'schema': api_shema, 'datasource': { 'source': 'api', 'filter': {'_type': 'line'}, 'aggregation': {'pipeline': [{'$geonear':{'near':{'type': 'point', 'coordinates': '$coords'},'distancefield': 'distance','maxdistance': '$maxdist','num': 1, 'spherical': 'true'}}]} }, }
Comments
Post a Comment