Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
somq opened this issue Aug 23, 2019 · 4 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@somq
Copy link

somq commented Aug 23, 2019

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

  • parse-server >= 3.3.0 with count=1&where={...$nearSphere... error is MongoError: radius must be a non-negative number (example query)

  • parse-server >= 3.3.0 with count=1&where={...$nearSphere... error is error: Uncaught internal server error.can't parse extra field: $maxDistance: 0.002525890376357666 (example query)

  • parse-server > 3.0.0 & < 3.3.0 With count=1&where={...$nearSphere... error is $nearSphere is not allowed inside of a $match aggregation expression (example query)

  • Works with 3.0.0

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

  • Server

    • parse-server version 3.7.2 (KO with any version > 3.0.0)
    • Operating System: Debian9
    • Hardware: bare-metal
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): local
  • Database

    • MongoDB version: Percona Server for MongoDB shell version v3.4.18-2.16
    • Storage engine: engine: rocksdb
    • Hardware: bare-metal
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): local

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 davimacedo added type:bug Impaired feature or lacking behavior that is likely assumed needs investigation labels Aug 23, 2019
@davimacedo
Copy link
Member

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

@somq
Copy link
Author

somq commented Aug 23, 2019

@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
Copy link
Member

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
Copy link
Member

dplewis commented Oct 11, 2019

I believe this has already been addressed as of 3.3.0.

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants