I had been getting the referenced error under version 2.4 with a different lon/lat data set. I upgraded to 2.6 and was able to use 2dsphere index on that data set. However, with a different data set (excerpt below) I received the old error message on trying to index using 2dshpere. the error message excerpt is as follows:
I am having the same problem receiving the error: can't extract geokeys from object; malformed geometry?. The object is the following, which validated on on GeoJSONLint.com. Also, I am using mongodb version 2.6.1. This happened to me recently when I was using version 2.4, and I upgraded to 2.6, and that solved the problem then, but I am getting the error again with a new geojson data set. Please, if anyone can let me know how to solve that would be very helpful.
{"type":"Feature",
"geometry": {
"type":"Polygon",
"coordinates": [[[-80.341942, 25.935059],[-80.341995, 25.936712],[-80.342026, 25.937851],[-80.342026, 25.938393],[-80.34211, 25.939489],[-80.342178, 25.942131],[-80.342308, 25.942329],[-80.342339, 25.94285],[-80.342438, 25.944914],[-80.342445, 25.945118],[-80.342514, 25.947062],[-80.342537, 25.947479],[-80.342613, 25.949152],[-80.342667, 25.950306],[-80.342712, 25.951366],[-80.342773, 25.952713],[-80.342857, 25.954611],[-80.341438, 25.955782],[-80.340202, 25.956839],[-80.339104, 25.957079],[-80.33831, 25.957081],[-80.336006, 25.957088],[-80.333244, 25.957096],[-80.331787, 25.957102],[-80.326721, 25.957117],[-80.326714, 25.957117],[-80.32444, 25.957127],[-80.323616, 25.957129],[-80.322365, 25.957132],[-80.318619, 25.957146],[-80.317375, 25.95715],[-80.316597, 25.957151],[-80.314278, 25.957161],[-80.313507, 25.957163],[-80.3134, 25.957163],[-80.31308, 25.957165],[-80.312973, 25.957167],[-80.312798, 25.957167],[-80.312263, 25.957167],[-80.312088, 25.957167],[-80.311996, 25.957167],[-80.311737, 25.957167],[-80.311646, 25.957169],[-80.311531, 25.957169],[-80.311272, 25.95717],[-80.311188, 25.95717],[-80.311073, 25.95717],[-80.311028, 25.95717],[-80.310913, 25.95717],[-80.310883, 25.95717],[-80.310837, 25.95717],[-80.310829, 25.95717],[-80.310783, 25.95717],[-80.310776, 25.95717],[-80.310738, 25.957169],[-80.310684, 25.957167],[-80.310646, 25.957165],[-80.310616, 25.957165],[-80.310547, 25.957163],[-80.310356, 25.957161],[-80.310287, 25.957159],[-80.310249, 25.957157],[-80.310143, 25.957155],[-80.310104, 25.957155],[-80.302231, 25.95697],[-80.301704, 25.956972],[-80.298981, 25.956896],[-80.301468, 25.956968],[-80.298668, 25.956886],[-80.29528, 25.956772],[-80.295052, 25.95677],[-80.294975, 25.95677],[-80.294975, 25.956905],[-80.294975, 25.956928],[-80.294762, 25.956938],[-80.29454, 25.956947],[-80.294548, 25.956835],[-80.294579, 25.954868],[-80.294579, 25.954702],[-80.294601, 25.953625],[-80.294601, 25.953461],[-80.294571, 25.953079],[-80.294502, 25.95186],[-80.294487, 25.95163],[-80.294472, 25.951212],[-80.294418, 25.949945],[-80.294296, 25.946936],[-80.294281, 25.946581],[-80.294197, 25.944429],[-80.294128, 25.943003],[-80.294098, 25.942413],[-80.29409, 25.94228],[-80.293854, 25.939285],[-80.293846, 25.939144],[-80.293694, 25.936041],[-80.293625, 25.934875],[-80.293549, 25.933006],[-80.293541, 25.932341],[-80.293533, 25.931826],[-80.293472, 25.931252],[-80.293495, 25.93054],[-80.293373, 25.928652],[-80.293343, 25.928129],[-80.293335, 25.927803],[-80.29332, 25.92738],[-80.293228, 25.925432],[-80.295456, 25.925182],[-80.296936, 25.925102],[-80.297676, 25.925114],[-80.297974, 25.925117],[-80.298866, 25.925131],[-80.30027, 25.925121],[-80.300957, 25.925116],[-80.305336, 25.925138],[-80.306831, 25.925156],[-80.307472, 25.925163],[-80.307686, 25.925158],[-80.308235, 25.92514],[-80.30941, 25.925127],[-80.309402, 25.924763],[-80.313126, 25.924776],[-80.318581, 25.924747],[-80.319275, 25.924746],[-80.319557, 25.924723],[-80.320023, 25.924686],[-80.320137, 25.924664],[-80.320526, 25.924587],[-80.320992, 25.924469],[-80.321259, 25.9244],[-80.321419, 25.924341],[-80.321869, 25.92417],[-80.322388, 25.923891],[-80.32254, 25.923805],[-80.322746, 25.923674],[-80.323059, 25.923479],[-80.323067, 25.923475],[-80.323181, 25.923376],[-80.323235, 25.92333],[-80.32373, 25.922907],[-80.324226, 25.922354],[-80.324783, 25.921375],[-80.324966, 25.920954],[-80.32531, 25.921684],[-80.325325, 25.922615],[-80.32534, 25.923359],[-80.32534, 25.923492],[-80.325348, 25.923607],[-80.325356, 25.923817],[-80.325371, 25.924597],[-80.325401, 25.925245],[-80.325432, 25.925819],[-80.325439, 25.92606],[-80.325462, 25.926447],[-80.325447, 25.926756],[-80.325409, 25.927439],[-80.325562, 25.92762],[-80.325706, 25.927801],[-80.325928, 25.92808],[-80.326218, 25.927971],[-80.326492, 25.927883],[-80.327003, 25.927832],[-80.33033, 25.927818],[-80.333618, 25.927853],[-80.334419, 25.927872],[-80.336128, 25.927896],[-80.336777, 25.927883],[-80.338219, 25.927912],[-80.339294, 25.927912],[-80.33963, 25.927931],[-80.340416, 25.927938],[-80.340919, 25.927923],[-80.341103, 25.927925],[-80.341606, 25.927925],[-80.34166, 25.929146],[-80.341721, 25.930458],[-80.341728, 25.930592],[-80.341766, 25.931606],[-80.341858, 25.933409],[-80.341942, 25.935059]
]]},
"properties":{
"id": "ZIP33015","census_year": 2010,"exposure_year": 2014, "commercial_exposure": 652653581, "residential_exposure": 2299303204, "mobile_home": 0, "tenants": 8631577, "condo_owners": 49223035, "total_exposure": 3009811397}}
When I run db.exposureByZip.ensureIndex({"geometry" : "2dsphere"}) on the above, I get the following error:
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"ok" : 0,
"errmsg" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('53a6be43beeb0a0246ae75bb'), geometry: { type: \"Polygon\", coordinates: [ [ [ -80.341942, 25.935059 ], [ -80.341995, 25.936712 ], [ -80.342026, 25.937851 ], [ -80.342026, 25.938393 ], [ -80.34211000000001, 25.939489 ], [ -80.342178, 25.942131 ], [ -80.342308, 25.942329 ], [ -80.342339, 25.94285 ], [ -80.342438, 25.944914 ], [ -80.342445, 25.945118 ], [ -80.34251399999999, 25.947062 ], [ -80.34253699999999, 25.947479 ], [ -80.342613, 25.949152 ], [ -80.34266700000001, 25.950306 ], [ -80.34271200000001, 25.951366 ], [ -80.34277299999999, 25.952713 ], [ -80.342857, 25.954611 ], [ -80.341438, 25.955782 ], [ -80.34020200000001, 25.956839 ], [ -80.33910400000001, 25.957079 ], [ -80.33831000000001, 25.957081 ], [ -80.336006, 25.957088 ], [ -80.33324399999999, 25.957096 ], [ -80.33178700000001, 25.957102 ], [ -80.32672100000001, 25.957117 ], [ -80.326714, 25.957117 ], [ -80.32444, 25.957127 ], [ -80.323616, 25.957129 ], [ -80.322365, 25.957132 ], [ -80.318619, 25.957146 ], [ -80.317375, 25.95715 ], [ -80.316597, 25.957151 ], [ -80.314278, 25.957161 ], [ -80.313507, 25.957163 ], [ -80.3134, 25.957163 ], [ -80.31308, 25.957165 ], [ -80.312973, 25.957167 ], [ -80.312798, 25.957167 ], [ -80.312263, 25.957167 ], [ -80.312088, 25.957167 ], [ -80.31199599999999, 25.957167 ], [ -80.31173699999999, 25.957167 ], [ -80.311646, 25.957169 ], [ -80.311531, 25.957169 ], [ -80.311272, 25.95717 ], [ -80.311188, 25.95717 ], [ -80.31107299999999, 25.95717 ], [ -80.31102799999999, 25.95717 ], [ -80.310913, 25.95717 ], [ -80.310883, 25.95717 ], [ -80.31083700000001, 25.95717 ], [ -80.310829, 25.95717 ], [ -80.310783, 25.95717 ], [ -80.310776, 25.95717 ], [ -80.310738, 25.957169 ], [ -80.31068399999999, 25.957167 ], [ -80.31064600000001, 25.957165 ], [ -80.310616, 25.957165 ], [ -80.310547, 25.957163 ], [ -80.310356, 25.957161 ], [ -80.310287, 25.957159 ], [ -80.310249, 25.957157 ], [ -80.310143, 25.957155 ], [ -80.310104, 25.957155 ], [ -80.30223100000001, 25.95697 ], [ -80.301704, 25.956972 ], [ -80.298981, 25.956896 ], [ -80.301468, 25.956968 ], [ -80.29866800000001, 25.956886 ], [ -80.29528000000001, 25.956772 ], [ -80.295052, 25.95677 ], [ -80.29497499999999, 25.95677 ], [ -80.29497499999999, 25.956905 ], [ -80.29497499999999, 25.956928 ], [ -80.29476200000001, 25.956938 ], [ -80.29454, 25.956947 ], [ -80.29454800000001, 25.956835 ], [ -80.294579, 25.954868 ], [ -80.294579, 25.954702 ], [ -80.294601, 25.953625 ], [ -80.294601, 25.953461 ], [ -80.294571, 25.953079 ], [ -80.29450199999999, 25.95186 ], [ -80.294487, 25.95163 ], [ -80.294472, 25.951212 ], [ -80.29441799999999, 25.949945 ], [ -80.294296, 25.946936 ], [ -80.294281, 25.946581 ], [ -80.294197, 25.944429 ], [ -80.294128, 25.943003 ], [ -80.29409800000001, 25.942413 ], [ -80.29409, 25.94228 ], [ -80.293854, 25.939285 ], [ -80.293846, 25.939144 ], [ -80.293694, 25.936041 ], [ -80.29362500000001, 25.934875 ], [ -80.293549, 25.933006 ], [ -80.293541, 25.932341 ], [ -80.293533, 25.931826 ], [ -80.29347199999999, 25.931252 ], [ -80.29349499999999, 25.93054 ], [ -80.293373, 25.928652 ], [ -80.29334299999999, 25.928129 ], [ -80.293335, 25.927803 ], [ -80.29331999999999, 25.92738 ], [ -80.293228, 25.925432 ], [ -80.295456, 25.925182 ], [ -80.296936, 25.925102 ], [ -80.297676, 25.925114 ], [ -80.297974, 25.925117 ], [ -80.298866, 25.925131 ], [ -80.30027, 25.925121 ], [ -80.300957, 25.925116 ], [ -80.305336, 25.925138 ], [ -80.306831, 25.925156 ], [ -80.307472, 25.925163 ], [ -80.307686, 25.925158 ], [ -80.308235, 25.92514 ], [ -80.30941, 25.925127 ], [ -80.30940200000001, 25.924763 ], [ -80.313126, 25.924776 ], [ -80.31858099999999, 25.924747 ], [ -80.319275, 25.924746 ], [ -80.319557, 25.924723 ], [ -80.32002300000001, 25.924686 ], [ -80.320137, 25.924664 ], [ -80.320526, 25.924587 ], [ -80.320992, 25.924469 ], [ -80.321259, 25.9244 ], [ -80.32141900000001, 25.924341 ], [ -80.32186900000001, 25.92417 ], [ -80.322388, 25.923891 ], [ -80.32254, 25.923805 ], [ -80.322746, 25.923674 ], [ -80.323059, 25.923479 ], [ -80.32306699999999, 25.923475 ], [ -80.32318100000001, 25.923376 ], [ -80.323235, 25.92333 ], [ -80.32373, 25.922907 ], [ -80.324226, 25.922354 ], [ -80.324783, 25.921375 ], [ -80.324966, 25.920954 ], [ -80.32531, 25.921684 ], [ -80.32532500000001, 25.922615 ], [ -80.32534, 25.923359 ], [ -80.32534, 25.923492 ], [ -80.32534800000001, 25.923607 ], [ -80.325356, 25.923817 ], [ -80.325371, 25.924597 ], [ -80.325401, 25.925245 ], [ -80.32543200000001, 25.925819 ], [ -80.325439, 25.92606 ], [ -80.325462, 25.926447 ], [ -80.325447, 25.926756 ], [ -80.32540899999999, 25.927439 ], [ -80.32556200000001, 25.92762 ], [ -80.325706, 25.927801 ], [ -80.325928, 25.92808 ], [ -80.326218, 25.927971 ], [ -80.326492, 25.927883 ], [ -80.327003, 25.927832 ], [ -80.33033, 25.927818 ], [ -80.333618, 25.927853 ], [ -80.334419, 25.927872 ], [ -80.336128, 25.927896 ], [ -80.336777, 25.927883 ], [ -80.338219, 25.927912 ], [ -80.339294, 25.927912 ], [ -80.33963, 25.927931 ], [ -80.340416, 25.927938 ], [ -80.340919, 25.927923 ], [ -80.341103, 25.927925 ], [ -80.341606, 25.927925 ], [ -80.34166, 25.929146 ], [ -80.34172100000001, 25.930458 ], [ -80.341728, 25.930592 ], [ -80.34176600000001, 25.931606 ], [ -80.341858, 25.933409 ], [ -80.341942, 25.935059 ] ] ] }, type: \"Feature\", properties: { commercial_exposure: 652653581, total_exposure: 3009811397, condo_owners: 49223035, mobile_home: 0, census_year: 2010, tenants: 8631577, residential_exposure: 2299303204, exposure_year: 2014, id: \"ZIP33015\" } }",
"code" : 16755
}
There is a bug posted for this problem: https://jira.mongodb.org/browse/SERVER-13735
“Malformed geometry” error when creating a geosphere index for a valid
MultiPolygon
Similar issue, a valid GeoJSON is being submitted for a 2dsphere index and is causing the "Can't extract geo keys from object, malformed geometry?" error.
There have been a series of previous bugs where valid GeoJSON was causing this error message. They've fixed those in 2.6.x but this appears to be a new one. I'd chime in on JIRA as it will help get it prioritized for a fix.
Maybe the problem is because your polygon coordinates has the first coordinate and last coordinate as the same value. Try to remove the last coordinate pooint from your polygons.