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

fix aggregate geoNear with date query #6540

Conversation

mtrezza
Copy link
Member

@mtrezza mtrezza commented Mar 27, 2020

added failing test case

  • this is the test case only without fix

@mtrezza mtrezza changed the title fix bug for aggregate geoNear with date query fix aggregate geoNear with date query Mar 27, 2020
- geoNear stages were not parsed for date fields, but mongodb nodejs adapter requires date object
@codecov
Copy link

codecov bot commented Mar 27, 2020

Codecov Report

Merging #6540 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6540      +/-   ##
==========================================
- Coverage   94.02%   94.01%   -0.01%     
==========================================
  Files         169      169              
  Lines       11848    11850       +2     
==========================================
+ Hits        11140    11141       +1     
- Misses        708      709       +1     
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 93.49% <100.00%> (+0.02%) ⬆️
src/RestWrite.js 93.64% <0.00%> (-0.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13bda61...3499dd9. Read the comment docs.

@mtrezza
Copy link
Member Author

mtrezza commented Mar 27, 2020

@dplewis Could you take a look at this?

Test before the fix failed as expected.
Test after the fix fails with:

Unhandled promise rejection: TypeError: Cannot read property 'split' of undefined

I cannot find out where that split is.
Interestingly, the fix works locally with a query from cloud code, geoNear returns the correct results.

@dplewis
Copy link
Member

dplewis commented Mar 27, 2020

What version of Mongo are you running locally?

@mtrezza
Copy link
Member Author

mtrezza commented Mar 27, 2020 via email

mtrezza added 2 commits March 27, 2020 03:45
- the geoNear object contains parameter keys which could be identical to field names in the collection, which should not be parsed and changed, therefore restricting parsing only to query parameter key
@mtrezza
Copy link
Member Author

mtrezza commented Mar 27, 2020

I am using VS Code to debug, but I didn't manage to set breakpoints when testing, or even run only a single test using the Test Explorer instead of all tests of a file with npm test x.spec.js. Therefore I am having a hard time to find the issue.

@mtrezza
Copy link
Member Author

mtrezza commented Mar 28, 2020

@dplewis Any help appreciated, I am stuck here unfortunately :/

@mtrezza
Copy link
Member Author

mtrezza commented Mar 28, 2020

@dplewis I should clarify that the test fails also locally with he same error.
I tried it with mongodb 4.0.4 mmapv1 and mongodb 4.2.3 wiredTiger.

However, the code fix itself works and returns the correct results when running a query in cloud code.
So maybe the test only fails because of some mock up for the test environment.

mtrezza added 7 commits March 29, 2020 04:30
- required to create geo index for geoNear test
- test case likey failed due to date rounding
- temporary, to find out why test fails on mongodb 3.6.9
- results were not ordered properly, so test validation failed sometimes
@mtrezza
Copy link
Member Author

mtrezza commented Mar 29, 2020

The geo near query failed due to missing geo index, which is required for geoNear.

Ready to merge.

@mtrezza
Copy link
Member Author

mtrezza commented Mar 29, 2020

@acinader Can we get this into the next release?

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dplewis dplewis merged commit 19dea5b into parse-community:master Mar 29, 2020
@matheusdavidson
Copy link

Hey Guys, i think this broke geoNear.

I had parse-server@4.2.0 installed here when i tried to use geoNear aggregation with a very basic query and got this error: MongoError: query must be an object

I tried the same query directly on mongo and it worked, the query was very basic just to test, after searching i saw that this PR changed geoNear so i tried the version before(4.1.0) and it worked with the same query, went back again to 4.2.0 to confirm and got the same error.

This is the pipeline i was trying:

const query: any[] = [
    {
        geoNear: {
            near: [-73.99279, 40.719296],
            distanceField: 'distance',
            maxDistance: 1000,
            spherical: true
        }
    }
];

@mtrezza @dplewis

@matheusdavidson
Copy link

I'm running mongo v4.2.3 and node v12.16.1 by the way.

@matheusdavidson
Copy link

I think maybe you forced the query option(which is optional) to be passed to the geoNear object so as i'm not using it, its value is not an object, maybe thats why the error says query must be an object.

@mtrezza
Copy link
Member Author

mtrezza commented May 20, 2020

@matheusdavidson Thanks for reporting, can you please open a new issue regarding this and reference this PR? I will look into this in the meanwhile.

@mtrezza
Copy link
Member Author

mtrezza commented May 20, 2020

Interesting, I added test cases without the query parameter and tested against mongodb 4.0.4 and 4.2.3. and tests passed. #6696

@matheusdavidson
Copy link

Strange, had another team member with that same problem with a version of our app without downgrading to 4.1.0. geoNear won't work anymore in the latest version

@mtrezza
Copy link
Member Author

mtrezza commented May 28, 2020

@matheusdavidson Are you or your team member able to replicate or observe this currently? It could also depend on the version of nodejs or mongodb driver.

Sent with GitHawk

@mtrezza
Copy link
Member Author

mtrezza commented May 28, 2020

@matheusdavidson Can you please open an issue for this and post your findings there? If we discuss it here is only has limited visibility.

Sent with GitHawk

@matheusdavidson
Copy link

matheusdavidson commented May 30, 2020

i'm gonna do that. Just had the same problem now on another project using geoNear, will have to lock the version on 4.1.0 on all projects here.

@mtrezza
Copy link
Member Author

mtrezza commented Jul 27, 2020

@matheusdavidson Do you have any update on this issue? If not, I will go ahead and close the related PR.

@matheusdavidson
Copy link

Hey @mtrezza, i didn't had time to see why this is happening but i'm sure the PR broke geoNear as i stated, for now what i did was downgrade all the projects to 4.1.0. Had lots of late projects and couldn't spend more time on this. Will open an issue in the future.

mtrezza added a commit to mtrezza/parse-server that referenced this pull request Jul 27, 2020
@mtrezza
Copy link
Member Author

mtrezza commented Jul 27, 2020

@matheusdavidson Since I was not able to reproduce this issue with the test cases in #6696, I added a potential fix for this potential issue by changing:

if (stage.$geoNear) {
   stage.$geoNear.query = this._parseAggregateArgs(schema, stage.$geoNear.query);
}

to

if (stage.$geoNear && stage.$geoNear.query) {
   stage.$geoNear.query = this._parseAggregateArgs(schema, stage.$geoNear.query);
}

So stage.$geoNear.query is not set to undefined anymore.

It would be great if you could upgrade a project to Parse Server 4.2.0 to confirm that it fails and then deploy the Parse Server master branch with PR #6696 merged. Then we'd know for sure whether the issue is solved.

@matheusdavidson
Copy link

@mtrezza thank you for adding the fix, i will upgrade one of the projects and test today.

@mtrezza
Copy link
Member Author

mtrezza commented Jul 27, 2020

@matheusdavidson That would be great. Note that the PR is not merged into master yet, but you can use the PR branch.

@matheusdavidson
Copy link

Hey @mtrezza, sorry it took so long for me to test. That solves my problem, thank you for your efforts!!

@mtrezza
Copy link
Member Author

mtrezza commented Sep 8, 2020

@matheusdavidson Thanks for your feedback, glad it worked.

mtrezza added a commit that referenced this pull request Sep 8, 2020
* add test cases for geoNear aggregation

Test cases do not have the `query` parameter set in $geoNear aggregation stage. this is to test for a reported potential issue when the parameter is not set.

* fixed potential issue when setting the geoNear.query parameter to undefined

see dicussion in #6540

* fixed duplicate index name in test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants