Error 16755 - Mongo cannot extract geo keys

I start with mongo and node.js, and in the existing project we have a collection with shops with geolocs. I get the following error (I deleted some fields)

"code" : 16755, "errmsg" : "Can't extract geo keys: { _id: ObjectId('566990eea9c7a38740a305a3'), id: 50, guid: \"NL7a09b334-7524-102d-a4ef-00163e5faa0c\", version: 0, owner: 118, published: 1, loc: [ -9999, -9999 ], logo: \"69db95d0-d58d-40cf-80d3-ac80b8c86af8.png\" } can't project geometry into spherical CRS: [ -9999, -9999 ]" 

when I try $set to specify some values ​​in the store. I see that the values ​​-9999, -9999 are wrong, but when I try to replace it with (in Robomongo) other values, I get the same error. How can I fix this error, so I can edit the values ​​in loc and do $set ?

+8
mongodb geolocation
source share
1 answer

You are correct that the error is due to invalid geo-coordinates that you have in this document (see 2dsphere indices ).

Assuming this is the document you have:

 > db.test.find() { "_id": ObjectId("566990eea9c7a38740a305a3"), "id": 50, "guid": "NL7a09b334-7524-102d-a4ef-00163e5faa0c", "version": 0, "owner": 118, "published": 1, "loc": [ -9999, -9999 ], "logo": "69db95d0-d58d-40cf-80d3-ac80b8c86af8.png" } 

The easiest way is to use the mongo shell to perform the update using ObjectId and $set in the loc field . For example, setting the loc field to a valid coordinate (for example, [-73.97, 40.77]):

 > db.test.update({"_id": ObjectId("566990eea9c7a38740a305a3")}, {$set:{loc:[-73.97, 40.77]}}) Updated 1 existing record(s) in 1ms WriteResult({ "nMatched": 1, "nUpserted": 0, "nModified": 1 }) 

Note that in the example above, I use the _id field, which is guaranteed to be unique, so the update command will only update the exact document. After that, your 2dsphere index creation should succeed:

 > db.test.createIndex({loc:'2dsphere'}) { "createdCollectionAutomatically": false, "numIndexesBefore": 1, "numIndexesAfter": 2, "ok": 1 } 
0
source share

All Articles