Skip to content

fix aggregate geoNear with date query#6540

Merged
dplewis merged 12 commits into
parse-community:masterfrom
mtrezza:fix-aggregate-geonear-with-query-date-field
Mar 29, 2020
Merged

fix aggregate geoNear with date query#6540
dplewis merged 12 commits into
parse-community:masterfrom
mtrezza:fix-aggregate-geonear-with-query-date-field

Conversation

@mtrezza

@mtrezza mtrezza commented Mar 27, 2020

Copy link
Copy Markdown
Member

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

codecov Bot commented Mar 27, 2020

Copy link
Copy Markdown

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

mtrezza commented Mar 27, 2020

Copy link
Copy Markdown
Member Author

@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

dplewis commented Mar 27, 2020

Copy link
Copy Markdown
Member

What version of Mongo are you running locally?

@mtrezza

mtrezza commented Mar 27, 2020 via email

Copy link
Copy Markdown
Member Author

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

mtrezza commented Mar 27, 2020

Copy link
Copy Markdown
Member Author

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

mtrezza commented Mar 28, 2020

Copy link
Copy Markdown
Member Author

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

@mtrezza

mtrezza commented Mar 28, 2020

Copy link
Copy Markdown
Member Author

@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

mtrezza commented Mar 29, 2020

Copy link
Copy Markdown
Member Author

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

Ready to merge.

@mtrezza

mtrezza commented Mar 29, 2020

Copy link
Copy Markdown
Member Author

@acinader Can we get this into the next release?

@dplewis dplewis left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown

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
Copy Markdown

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

@matheusdavidson

Copy link
Copy Markdown

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

mtrezza commented May 20, 2020

Copy link
Copy Markdown
Member Author

@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

mtrezza commented May 20, 2020

Copy link
Copy Markdown
Member Author

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
Copy Markdown

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

mtrezza commented May 28, 2020

Copy link
Copy Markdown
Member Author

@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

mtrezza commented May 28, 2020

Copy link
Copy Markdown
Member Author

@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

matheusdavidson commented May 30, 2020

Copy link
Copy Markdown

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

mtrezza commented Jul 27, 2020

Copy link
Copy Markdown
Member Author

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

@matheusdavidson

Copy link
Copy Markdown

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

mtrezza commented Jul 27, 2020

Copy link
Copy Markdown
Member Author

@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
Copy Markdown

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

@mtrezza

mtrezza commented Jul 27, 2020

Copy link
Copy Markdown
Member Author

@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
Copy Markdown

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

@mtrezza

mtrezza commented Sep 8, 2020

Copy link
Copy Markdown
Member Author

@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