tarmes
tarmes

Reputation: 15442

Unable to add 2dSphere index to array of locations

I'm trying to add an 2dSphere index to a Mongo Collection that contains an array of locations. This is the error I'm getting:

[MongoError: insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?:
   { _id: "gjuFiwHd7ctBpgEwL",
     title: "Iny orple taoland.",
     locations: [
         { loc: 
             { type: "Point", coordinates: [ "0.0181033", "43.8355792" ] }
         }
     ]
   }
]

Where I'm calling:

ensureIndex({ 'locations.loc': "2dsphere" })

What am I doing wrong?

Upvotes: 2

Views: 354

Answers (1)

Abdullah Rasheed
Abdullah Rasheed

Reputation: 3752

For 2dsphere, points are specified in GeoJSON format. A point is give by a two-element array, representing[longitude,latitude]. You should change your coordinates array.

The lon and lat points shouldn't be wrapped in double qoutes.

It should be:

{ type: "Point", coordinates: [ 0.0181033, 43.8355792] }

Upvotes: 2

Related Questions