Repository navigation
withinKilometers withinMiles withinRadians not working with Live Query #7480
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
I want to retrieve object only in a specific radius of the user current Position.
I use Live Query to get when object enter, update, leave theses conditions in real time.
However when i write a query with withinKilometers / withinMiles / withinRadians the Live Query never triggered when the Object has his GeoPoint enter / update / leave the specific radius.
Steps to reproduce
- Setup a parse-server with Live Query
- Create a class with a GeoPoint column (in my example, my column is "location")
- Create a client, i tried on Parse Flutter SDK and Parse Javascript SDK
- Connect the client, make a Parse Query with a subscription based on withinKilometers / withinMiles / withinRadians conditions
My javascript example :
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="https://unpkg.com/parse/dist/parse.js"></script>
<script>
main();
async function main() {
Parse.initialize("xxxxxxxxxxxxx");
Parse.serverURL = 'http://192.168.X.X:1337/parse'
var query = new Parse.Query('TestObject');
query.withinKilometers("location", new Parse.GeoPoint({latitude: 45, longitude: 2}), 1, false);
var subscription = await query.subscribe();
subscription.on('open', () => {
console.log('subscription opened');
});
subscription.on('update', (object) => {
console.log(object);
console.log('object updated');
});
subscription.on('enter', (object) => {
console.log(object);
console.log('enter updated');
});
subscription.on('leave', (object) => {
console.log(object);
console.log('object left');
});
subscription.on('delete', (object) => {
console.log(object);
console.log('object deleted');
});
subscription.on('close', () => {
console.log('subscription closed');
});
}
</script>
</head>
<body>
<p>Test</p>
</body>
</html>
Actual Outcome
My Live Query subscription is never triggered when the GeoPoint respect the subscription conditions.
If i replace the .subscription() by .find() the query worked fine, but this is not i want cause i need Live Query
Expected Outcome
I expect to get my TestObject when his location is update and still respect my subscription condition.
In my example : a TestObject with "location" Parse.GeoPoint({latitude: 45, longitude: 2}) must be return to client because the client have the same position and the withinKilometers is respected.
(see my example line query.withinKilometers("location", new Parse.GeoPoint({latitude: 45, longitude: 2}), 1, false);)
Failing Test Case / Pull Request
- 🤩 I submitted a PR with a fix and a test case.
- 🧐 I submitted a PR with a failing test case.
Environment
Server
- Parse Server version:
4.5.0 - Operating system:
Windows 10.0.19043 - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
local
Database
- System (MongoDB or Postgres):
MongoDB - Database version:
4.4.4 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
Local
Clients
- SDK JavaScript version:
3.3.0 - SDK Flutter version:
3.1.0
Logs
No log
Regards !
Activity
mtrezza commentedon Aug 4, 2021
Thanks for reporting! Could you add a failing test to demonstrate the issue?
PolSpock commentedon Aug 4, 2021
Hi, after new testing i found new elements :
With Parse JavasScript SDK :
If you give the last parameter of withinKilometers (sorted) :
query.withinKilometers("location", new Parse.GeoPoint({ latitude: 45.0, longitude: 2.0 }), 2, false);The request to register the subscription to the server will be :
{"op":"subscribe","requestId":1,"query":{"className":"TestObject","where":{"location":{"$geoWithin":{"$centerSphere":[[2,45],0.0003139224611520954]}}}}}This not working
However, if you not specify the last parameter of withinKilometers :
query.withinKilometers("location", new Parse.GeoPoint({ latitude: 45.0, longitude: 2.0 }), 2);The subscription request to the server will be :
{"op":"subscribe","requestId":1,"query":{"className":"TestObject","where":{"location":{"$nearSphere":{"__type":"GeoPoint","latitude":45,"longitude":2},"$maxDistance":0.0003139224611520954}}}}And this working
However with Parse Flutter SDK :
The following code :
Generate the cURL request which not working too :
So i see they are different result of request between Javascript SDK and Flutter SDK
$maxDistanceparameter working but$maxDistanceInKilometersand$geoWithin":"$centerSpheredoesn'tTest with Jasmine in /spec folder on parse-server repo :
Not working test :
Working test :
EDITED :
On Parse Flutter SDK, if i override this method
By :
The override works : but you have to convert kilometers in maxDistance (see there)
So i really think they are a problem with Live Query and Parse Javascript SDK / Parse Flutter SDK parameters
EDITED 2 :
So i've seen in the parse-server source code these lines :
So $maxDistanceInKilometers $maxDistanceInMiles $maxDistanceInRadians must have to be converted to $maxDistance but it doesn't seems to work :/
EDITED 3 :
If you add log on these lines, the query.find() request will fire correctly the
console.log("i'm here");but nothing appear with a Live Querygithub-actions commentedon Aug 27, 2021
🤖 Parsy
Thanks for opening this issue!
I'm in beta, so forgive me if I'm still making mistakes.
mtrezza commentedon Aug 27, 2021
@PolSpock Never mind, that message was because this issue was written with an old template. I guess the bot should only comment on newly opened issues.
cbaker6 commentedon Aug 29, 2021
I'm sure this has something to do with LiveQuery currently not supporting all query operators. More info here, specifically:
Though there has been additional support added in #7113
You can see that
$maxDistanceis supported here:parse-server/src/LiveQuery/QueryTools.js
Lines 305 to 311 in 1e0d408
While
$centerSphereisn't:parse-server/src/LiveQuery/QueryTools.js
Lines 336 to 340 in 1e0d408
When it comes to the Flutter SDK using
$maxDistanceInKilometers, searching the reference files above shows that isn't supported by LiveQuery currently either.You may want to open a PR to add support or edit your exiting PR.
cbaker6 commentedon Aug 29, 2021
@mtrezza this should probably be labeled as an "enhancement" since it's known these operators aren't supported currently