parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.84k stars 4.77k forks source link

Queries with a `where $nearSphere` operator AND a `count operator` returns a mongo error with parse-server > 3.0.0. #5961

Open somq opened 5 years ago

somq commented 5 years ago

Issue Description

On parse-server > 3.0.0, when querying a Class with a Geopoint filtered with $nearSphere and a count operator, mongodb returns an errors which is returned as an internal server error by parse-server.

Queries

Queries does not return the same message depending on the parse-server version

Steps to reproduce

Note: This (example query) with a count=1 in front of the where=...

curl -X GET \
  -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -G \
  --data-urlencode 'count=1&where={
        "location": {
          "$nearSphere": {
            "__type": "GeoPoint",
            "latitude": 30.0,
            "longitude": -20.0
          },
          "$maxDistanceInMiles": 10.0
        }
      }' \
  https://YOUR.PARSE-SERVER.HERE/parse/classes/PlaceObject

Expected Results

What's in the doc: https://docs.parseplatform.org/rest/guide/#counting-objects

{
  "results": [],
  "count": 1337
}

Actual Outcome

Environment Setup

Logs/Trace

0|parse-se | 2019-08-23 12:18 +02:00: verbose: REQUEST for [GET] /v1/classes/Place?count=1&where={%20%20%20%20%20%20%20%20%22location%22:%20{%20%20%20%20%20%20%20%20%20%20%22$nearSphere%22:%20{%20%20%20%20%20%20%20%20%20%20%20%20%22__type%22:%20%22GeoPoint%22,%20%20%20%20%20%20%20%20%20%20%20%20%22latitude%22:%2030.0,%20%20%20%20%20%20%20%20%20%20%20%20%22longitude%22:%2020.0%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20}%20%20%20%20%20%20}: {} {"method":"GET","url":"/v1/classes/Place?count=1&where={        \"location\": {          \"$nearSphere\": {            \"__type\": \"GeoPoint\",            \"latitude\": 30.0,            \"longitude\": 20.0          }        }      }","headers":{"x-real-ip":"10.67.3.84","x-forwarded-for":"10.67.3.84","x-nginx-proxy":"true","host":"cobox-dev","connection":"close","sec-fetch-mode":"cors","x-parse-master-key":"REDACTED","x-parse-application-id":"OCPCoBox","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36","accept":"*/*","sec-fetch-site":"same-origin","referer":"https://cobox-dev/board/apps/OCPCoBox/api_console","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7","cookie":"session=eyJjc3JmU2VjcmV0IjoiTWg4MTRVNHpFZTRudGpOendmOU9YemhCIiwiZmxhc2giOnt9LCJwYXNzcG9ydCI6eyJ1c2VyIjoib2NwZGV2In19; session.sig=msvh6QgaSsSwAsLMt622KFguiKc"},"body":{}}
0|parse-se | 2019-08-23 12:18 +02:00: error: Uncaught internal server error.radius must be a non-negative number {"ok":0,"errmsg":"radius must be a non-negative number","code":2,"codeName":"BadValue","name":"MongoError","stack":"MongoError: radius must be a non-negative number\n    at Connection.<anonymous> (/opt/ocp/cube-parse-server/node_modules/mongodb-core/lib/connection/pool.js:443:61)\n    at Connection.emit (events.js:180:13)\n    at Connection.emit (domain.js:422:20)\n    at processMessage (/opt/ocp/cube-parse-server/node_modules/mongodb-core/lib/connection/connection.js:364:10)\n    at TLSSocket.<anonymous> (/opt/ocp/cube-parse-server/node_modules/mongodb-core/lib/connection/connection.js:533:15)\n    at TLSSocket.emit (events.js:180:13)\n    at TLSSocket.emit (domain.js:422:20)\n    at addChunk (_stream_readable.js:274:12)\n    at readableAddChunk (_stream_readable.js:261:11)\n    at TLSSocket.Readable.push (_stream_readable.js:218:10)\n    at TLSWrap.onread (net.js:581:20)"}
0|parse-se | 2019-08-23 12:18 +02:00: MongoError: radius must be a non-negative number
0|parse-se |     at Connection.<anonymous> (/opt/ocp/cube-parse-server/node_modules/mongodb-core/lib/connection/pool.js:443:61)
0|parse-se |     at Connection.emit (events.js:180:13)
0|parse-se |     at Connection.emit (domain.js:422:20)
0|parse-se |     at processMessage (/opt/ocp/cube-parse-server/node_modules/mongodb-core/lib/connection/connection.js:364:10)
0|parse-se |     at TLSSocket.<anonymous> (/opt/ocp/cube-parse-server/node_modules/mongodb-core/lib/connection/connection.js:533:15)
0|parse-se |     at TLSSocket.emit (events.js:180:13)
0|parse-se |     at TLSSocket.emit (domain.js:422:20)
0|parse-se |     at addChunk (_stream_readable.js:274:12)
0|parse-se |     at readableAddChunk (_stream_readable.js:261:11)
0|parse-se |     at TLSSocket.Readable.push (_stream_readable.js:218:10)
0|parse-se |     at TLSWrap.onread (net.js:581:20)

Additonal notes:

Related to #5285?

davimacedo commented 5 years ago

@somq thanks for reporting. Do you mind to open a pr with a failing test case?

somq commented 5 years ago

@davimacedo Can you guide me through the steps please?
If I (dumbly) clone the repo, install mongo-db-runner and run npm run test, test complains that masterkey is missing etc...

davimacedo commented 5 years ago

Sure. Make sure that you are using Node.js >= 10 and try the following steps:

$ git clone https://github.com/parse-community/parse-server
$ cd parse-server # go into the clone directory
$ npm install # install all the node dependencies
$ npm run test # run tests
dplewis commented 4 years ago

I believe this has already been addressed as of 3.3.0.

https://github.com/parse-community/parse-server/pull/5286

We might have to update the documentation since you can't use nearSphere and count but use $geoWithin and count. This should be transformed thanks to the PR.