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 }
Kevin adistambha
source share