[SERVER-11293] Can't extract geo keys from object, malformed geometry? Created: 21/Oct/13  Updated: 04/Nov/13  Resolved: 31/Oct/13

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 2.4.6, 2.5.3
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Edgardo Vega Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: indexing
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Operating System: Linux
Steps To Reproduce:

Insert the following polygon into a collection without an index.

"type": "Polygon",
"coordinates":[ [ [ -176.5573404206603, -26.62752545076926 ], [ -176.5790581155294, -26.45810909031957 ], [ -176.6707632150535, -25.96189875199764 ], [ -176.8290859572914, -25.15712799883819 ], [ -177.0482086728448, -24.07336864167018 ], [ -177.3200795588031, -22.75044410420587 ], [ -177.6347085473391, -21.23696608612408 ], [ -177.9805343970758, -19.58854829538924 ], [ -178.3448495182208, -17.86576288734291 ], [ -178.714266920998, -16.13191470250723 ], [ -179.0752121290624, -14.45071509014138 ], [ -179.4144219822276, -12.88394079437707 ], [ -179.7194319996838, -11.4891639286443 ], [ -179.9790343952361, -10.31763645191415 ], [ -180.1836899145046, -9.412406883018601 ], [ -180.3258783608655, -8.806738455571789 ], [ -180.4003749298368, -8.522886839391754 ], [ -180.4044421978278, -8.571282341822819 ], [ -180.3379307105011, -8.950146639488732 ], [ -180.2032844745671, -9.645558123911005 ], [ -180.0054511512106, -10.63196345982628 ], [ -179.7517002511473, -11.87311655866853 ], [ -179.4513560118511, -13.32341046404096 ], [ -179.1154547725442, -14.92955320820282 ], [ -178.7563394369255, -16.63252605916341 ], [ -178.38720592536, -18.36975220135411 ], [ -178.0216182824303, -20.07739616033413 ], [ -177.6730102575311, -21.69270947771339 ], [ -177.3541916732428, -23.15633644298238 ], [ -177.0768777202904, -24.41449515667321 ], [ -176.851258475444, -25.42095378030516 ], [ -176.685624460696, -26.13872935455922 ], [ -176.5860620027822, -26.54144676153235 ], [ -176.5573404206603, -26.62752545076926 ] ] ]
}

Then query the polygon using $geoIntersects. Everything works as expected.

Then create an index on the field and add the same polygon you will get the following error "Can't extract geo keys from object, malformed geometry?" when inserted the same data.

The polygon does pass the test on http://geojsonlint.com/

Participants:

 Description   

The same GeoJson polygon throws errors depending on if a 2dsphere geo index exists or not. Either the indexing need to be fixed not to throw this error or querying needs to have the same checks to throw the error to keep behavior the same.



 Comments   
Comment by A. Jesse Jiryu Davis [ 30/Oct/13 ]

This polygon includes longitudes less than -180, which we don't support. In summary,

  • We don't return an error if this polygon is inserted without a 2dsphere index, by design.
  • If this polygon is in a collection without a 2dsphere index, we silently skip it when querying the collection, also by design.
  • If this polygon is used as a predicate in a query the server returns "bad query: BadValue bad geo query" as expected.
  • If this polygon is in a collection and we then create a 2dsphere index, createIndex fails with "Can't extract geo keys from object, malformed geometry?", followed by a dump of the bad document, as expected.
  • If we create a 2dsphere index and then try to insert this polygon, the insert fails with an identical error, as expected.

In the near future we'd like to improve error messages to say why a polygon can't be parsed. But this particular ticket does not represent unexpected behavior.

Comment by A. Jesse Jiryu Davis [ 24/Oct/13 ]

Hi vegaed. To help us diagnose this issue, could you please provide an example of a polygon that MongoDB thinks intersects with this one? I find that if I insert your example polygon and search for it with $geoIntersects, I can't construct a polygon that MongoDB thinks intersects it:

var poly = {
    "type": "Polygon",
    "coordinates": [[
        [-176.5573404206603, -26.62752545076926],
        [-176.5790581155294, -26.45810909031957],
        [-176.6707632150535, -25.96189875199764],
        [-176.8290859572914, -25.15712799883819],
        [-177.0482086728448, -24.07336864167018],
        [-177.3200795588031, -22.75044410420587],
        [-177.6347085473391, -21.23696608612408],
        [-177.9805343970758, -19.58854829538924],
        [-178.3448495182208, -17.86576288734291],
        [-178.714266920998,  -16.13191470250723],
        [-179.0752121290624, -14.45071509014138],
        [-179.4144219822276, -12.88394079437707],
        [-179.7194319996838, -11.4891639286443],
        [-179.9790343952361, -10.31763645191415],
        [-180.1836899145046, -9.412406883018601],
        [-180.3258783608655, -8.806738455571789],
        [-180.4003749298368, -8.522886839391754],
        [-180.4044421978278, -8.571282341822819],
        [-180.3379307105011, -8.950146639488732],
        [-180.2032844745671, -9.645558123911005],
        [-180.0054511512106, -10.63196345982628],
        [-179.7517002511473, -11.87311655866853],
        [-179.4513560118511, -13.32341046404096],
        [-179.1154547725442, -14.92955320820282],
        [-178.7563394369255, -16.63252605916341],
        [-178.38720592536,   -18.36975220135411],
        [-178.0216182824303, -20.07739616033413],
        [-177.6730102575311, -21.69270947771339],
        [-177.3541916732428, -23.15633644298238],
        [-177.0768777202904, -24.41449515667321],
        [-176.851258475444,  -25.42095378030516],
        [-176.685624460696,  -26.13872935455922],
        [-176.5860620027822, -26.54144676153235],
        [-176.5573404206603, -26.62752545076926]]]
};
 
var searchPoly = {
    "type": "Polygon",
    "coordinates": [[
        [-178, -30],
        [-178, -10],
        [-177, -10],
        [-177, -30],
        [-178, -30]]]
};
 
db.test_collection.drop();
db.test_collection.insert({p: poly});
// prints "null"
printjson(db.test_collection.findOne({
    p: {$geoIntersects: {$geometry: searchPoly}}}));

Generated at Thu Feb 08 03:25:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.