Pub and sub for sorting a collection


#1

Hi all,

Im playing around with Microscope and adding a additional sorting by distance.
Theres no server error code but on the front end, the sort is not working as its returning all posts (rather than filtering those within a certain distance).

Occasionally this error on server side will also pop up but only upon the initial start up of server.

Exception from sub postsByDistance id TzLZsqkPJNnNaQEdo

Error: Exception while polling query {“collectionName”:“posts”,“selector”:{“location”:{"$near":{"$geometry":{“type”:“Point”,“coordinates”:[null,null]},"$maxDistance":500}}},“options”:{“transform”:null}}:

$near requires a point, given { type: “Point”, coordinates: [ null, null ] }

I have the data as per the format so not sure why error occurs. Someone suggested that it might be a race condition but I do not know how to assess or troubleshoot it.


#2

well, seems as you are not sanitizing your input, cause I would not expect [null, null] to be valid query

Edit: interesting that this thread pop to my “recent” ones so I did not noticed it’s age :smiley:


#3

Thanks, I inserted a check and that solved it! I wanted to delete the question and somehow appeared on the recent list.