javascript - MongoDB Malformed Geometry with geojson -


using mongodb v2.6.5

when attempt save geojson document db receive following error:

name: 'mongoerror',   code: 16755,   err: 'insertdocument :: caused :: 16755 can\'t extract geo keys object, malformed geometry?: { _id: objectid(\'55271b90d075728028d4c9e1\'), ..., location: [ { _id: objectid(\'55271b90d075728028d4c9e3\'), loc: { type: "point", coordinates: [ -105.01621, 39.57422 ] } } ] } ], status: [ "lead" ], created: new date(1428626320406), lastname: "doe", firstname: "john", __v: 0 }' } 

i'm attempting insert point table 2dsphere index, managed through mongoosejs shown below.

var geoaddressschema = new schema({     // holds points.     loc: {         type: { type: string },         coordinates: []     } });   var lead = new schema({     // other fields  ...     location: [geoaddressschema],     // ... });  leadaddressschema.index({ location: '2dsphere' }); 

the geojson being saved:

{ type: "point", coordinates: [ -111.855211, 33.58513 ] } 

the geojson valid according to: http://geojsonlint.com/ if wrap fields in quotes, should not need (and cannot mongo afaik).

anyone have idea why fail? looks correct.

reference links

mongodb geojson: http://docs.mongodb.org/manual/reference/geojson/

mongodb 2dsphere: http://docs.mongodb.org/manual/core/2dsphere/

first observation: need not introduce loc path in location structure.

further, need not define separate schema location field in lead schema.

try this:

var lead = new schema({   // other fields  ...   location: {     type: {       type: 'string',       default: 'point'  // , optionally skip including `type: string` everywhere     },     coordinates: {       type: [number]     }   },   // more fields ... });  leadaddressschema.index({ location: '2dsphere' }); 

another problem faced 2dsphere index gets messed up, when figuring , testing out solutions. try dropping index, or better collection after make structural changes schema.

> db.lead.drop();  // on mongo console` 

Popular posts from this blog