MongoDB error when using GeoPoint in cloud code

133 views
Skip to first unread message

Ye Min Htut

unread,
Aug 27, 2016, 12:23:57 AM8/27/16
to back{4}app
Hi,

I am getting a MongoDB error when using query.near("location",geoPoint).

My code:

var geoPoint  = new Parse.GeoPoint([lat,long]);
var query = new Parse.Query(Parse.User);
query
.near("location",geoPoint);
query
.find(...);

The log says:

Uncaught internal server error. { [MongoError: Can't canonicalize query: BadValue $geometry is required for geo near query] name: 'MongoError', message: 'Can\'t canonicalize query: BadValue $geometry is required for geo near query', '$err': 'Can\'t canonicalize query: BadValue $geometry is required for geo near query', code: 17287 } MongoError: Can't canonicalize query: BadValue $geometry is required for geo near query at Function.MongoError.create (/usr/src/app/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11) at queryCallback (/usr/src/app/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:182:34) at Callbacks.emit (/usr/src/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:119:3) at null.messageHandler (/usr/src/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:358:23) at Socket.<anonymous> (/usr/src/app/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:292:22) at emitOne (events.js:77:13) at Socket.emit (events.js:169:7) at readableAddChunk (_stream_readable.js:146:16) at Socket.Readable.push (_stream_readable.js:110:10) at TCP.onread (net.js:523:20)


The error code when calling that cloud code from REST Api:

{
 
"code": 141,
 
"error": {
   
"code": 1
 
}
}

My Application ID: PNSOCgF9Jom3inDRVxLPo0eNc97DaoVGrQN9XWLs

Thanks in advanced

Davi Macêdo

unread,
Sep 21, 2016, 1:14:08 PM9/21/16
to back{4}app
Hi,

Can you try to change this line here:
var geoPoint  = new Parse.GeoPoint([lat,long]);

To this one here?
var geoPoint  = new Parse.GeoPoint(lat,long);

Best!
Message has been deleted
Message has been deleted

ba...@me.com

unread,
Nov 8, 2016, 10:52:19 AM11/8/16
to back{4}app
I had the same issue.
In my case the variables lat and lng falsely has been of type String. 
Parse.GeoPoint() is returning a GeoPoint where _latitude and _longitude are Strings too. Using this GoePoint within a near or withinKilometers query resulting in the error of the mongodb. 

To check this out you can try creating your GeoPoint like this: 
var lat = parseFloat(req.params["latitude"]);
var lng = parseFloat(req.params["longitude"]);
var userLocation =  new Parse.GeoPoint();
userLocation.latitude = lat;
userLocation.longitude = lng;

hope this helps!
Message has been deleted

Davi Macêdo

unread,
Nov 8, 2016, 1:12:06 PM11/8/16
to back{4}app
Thank you for sharing your solution. Best!
Reply all
Reply to author
Forward
0 new messages