-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Add Polygon Type To Schema / PolygonContain to Query #3944
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3944 +/- ##
==========================================
+ Coverage 90.59% 90.68% +0.08%
==========================================
Files 116 116
Lines 7793 7889 +96
==========================================
+ Hits 7060 7154 +94
- Misses 733 735 +2
Continue to review full report at Codecov.
|
@flovilmart Done, Let me know if I need more tests |
Mongo only throws errors if indexes are set. I found that mongo throws an error for self-intersecting polygons. Is it ok if mongo just throws an error?
https://github.com/mongodb/mongo/blob/master/src/mongo/db/geo/geoparser.cpp#L223 I need to check for invalid loops if not users can set invalid polygons and could break once they add indexes later on. Maybe we can add geoJson validator dependencies to parse-server and sdks. Eventually we will need it for LineString, MultiPoint, MultiLineString,MultiPolygon,GeometryCollection |
Is it possible to enforce the indexing when adding those columns types the same way we do with 2D indexes? |
Since $geoIntersect doesn't require a index I can't catch an error to add one like $near. I could check the schema and if Polygon Type add an index on object creation. I'm going to write a few more test for postgres. It doesn't throw errors right now but It may for indexes. |
@flovilmart how does this look? |
I’ll have a deeper look after the 2.5.0 release :) |
Why the removal of the test, |
I noticed when a mongoError gets thrown it retries the request a few times. Is that normal? I added it back |
The JS SDK is retrying dumbly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks awesome @dplewis ! A few nits here and there before we get that one in!
@@ -25,6 +25,7 @@ function mongoFieldToParseSchemaField(type) { | |||
case 'geopoint': return {type: 'GeoPoint'}; | |||
case 'file': return {type: 'File'}; | |||
case 'bytes': return {type: 'Bytes'}; | |||
case 'polygon': return {type: 'Polygon'}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit alignment
@@ -98,6 +99,7 @@ function parseFieldTypeToMongoFieldType({ type, targetClass }) { | |||
case 'GeoPoint': return 'geopoint'; | |||
case 'File': return 'file'; | |||
case 'Bytes': return 'bytes'; | |||
case 'Polygon': return 'polygon'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit alignment
@@ -182,7 +182,8 @@ export class MongoStorageAdapter { | |||
|
|||
addFieldIfNotExists(className, fieldName, type) { | |||
return this._schemaCollection() | |||
.then(schemaCollection => schemaCollection.addFieldIfNotExists(className, fieldName, type)); | |||
.then(schemaCollection => schemaCollection.addFieldIfNotExists(className, fieldName, type)) | |||
.then(() => this.create2dsphereIndex(className, fieldName, type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rename create2dsphereIndex
into an umbrella createIndexesIfNeeded
? more explicit :)
|
||
create2dsphereIndex(className, fieldName, type) { | ||
if (type && type.type === 'Polygon') { | ||
const index = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use:
const index = {
[fieldName]: '2dsphere'
};
and remove the next line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works nicely. Thanks
Thanks for the feedback. Changes have been made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
#3942
Adds Mongo and PG support for Polygon Type and PolygonContain query