Skip to content

Unable to make a count on a query with a GeoConstraint #5285

Closed
@jlnquere

Description

@jlnquere

Issue Description

When I try to make a count on a query with a GeoConstraint, I have an internal server error. It seems to be tied to an issue with Mongo: MongoError: $nearSphere is not allowed inside of a $match aggregation expression.

Steps to reproduce

I built a minimal parse instance (just a copy paste of documentation):

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();

var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/minimal_parse', // Connection string for your MongoDB database
  appId: 'myAppId',
  masterKey: 'myMasterKey',
  serverURL: 'http://localhost:1337/parse',
});

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

app.listen(1337, function() {
  console.log('parse-server-example running on port 1337.');
});

On client side:

var Parse = require('parse/node');

const parseAppId = 'myAppId';
const parseMasterKey = "myMasterKey";
const parseServerURL = 'http://localhost:1337/parse';

Parse.serverURL = parseServerURL;
Parse.initialize(parseAppId, undefined, parseMasterKey);

let run = async () => {
  let t = new Parse.Object("Contact");
  t.set("geocode", new Parse.GeoPoint(0,0))
  t.set("tel", "33663192122")
  t.set("name", "test")
  await t.save({}, {useMasterKey:true})


  let query = new Parse.Query('Contact').withinKilometers("geocode", new Parse.GeoPoint(0, 0), 20)

  let items = await query.find()
  // "Got 1 items with find()"
  console.log("Got "+ items.length+" items with find().");  

  let itemsCount = await query.count()

  // Expecting "Got 1 items with find()", but got an error 
  console.log("Got "+ itemsCount+" items with count().");  
}

run()

Expected Results

I'm expecting query.count() to return a count.

Actual Outcome

Instead, the client got an internal server error. On server, I got this trance:

The request (so far, so good):

verbose: REQUEST for [GET] /parse/classes/Transporter: {
  "where": {
    "geocode": {
      "$nearSphere": {
        "__type": "GeoPoint",
        "latitude": 0,
        "longitude": 0
      },
      "$maxDistance": 0.0031392246115209545
    }
  },
  "limit": 0,
  "count": 1
} method=GET, url=/parse/classes/Transporter, user-agent=node-XMLHttpRequest, Parse/js2.1.0 (NodeJS 11.1.0), accept=*/*, content-type=text/plain, host=localhost:1337, content-length=270, connection=close, __type=GeoPoint, latitude=0, longitude=0, $maxDistance=0.0031392246115209545, limit=0, count=1

The error:

error: Uncaught internal server error. { MongoError: $nearSphere is not allowed inside of a $match aggregation expression
    at queryCallback (/Users/onejjy/Documents/Code/tmp/minimal_parse/node_modules/mongodb-core/lib/cursor.js:248:25)
    at /Users/onejjy/Documents/Code/tmp/minimal_parse/node_modules/mongodb-core/lib/connection/pool.js:532:18
    at process.internalTickCallback (internal/process/next_tick.js:70:11)
  ok: 0,
  errmsg:
   '$nearSphere is not allowed inside of a $match aggregation expression',
  code: 16426,
  name: 'MongoError',
  [Symbol(mongoErrorContextSymbol)]: {} } MongoError: $nearSphere is not allowed inside of a $match aggregation expression
    at queryCallback (/Users/onejjy/Documents/Code/tmp/minimal_parse/node_modules/mongodb-core/lib/cursor.js:248:25)
    at /Users/onejjy/Documents/Code/tmp/minimal_parse/node_modules/mongodb-core/lib/connection/pool.js:532:18
    at process.internalTickCallback (internal/process/next_tick.js:70:11)
MongoError: $nearSphere is not allowed inside of a $match aggregation expression
    at queryCallback (/Users/onejjy/Documents/Code/tmp/minimal_parse/node_modules/mongodb-core/lib/cursor.js:248:25)
    at /Users/onejjy/Documents/Code/tmp/minimal_parse/node_modules/mongodb-core/lib/connection/pool.js:532:18
    at process.internalTickCallback (internal/process/next_tick.js:70:11)

Environment Setup

  • Server

    • parse-server version: 3.1.3
    • Operating System: Tested on Mac OS and Ubuntu
    • Hardware: personal computer and production server
    • Localhost or remote server?: local and remote
  • Database

    • MongoDB version: 3.2.1
    • Storage engine: [FILL THIS OUT]
    • Hardware: personal computer and production server
    • Localhost or remote server? local and remote

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions