Използване на MongoDB v2.6.5
Когато се опитвам да запазя geojson документ в db, получавам следната грешка:
name: 'MongoError',
code: 16755,
err: 'insertDocument :: caused by :: 16755 Can\'t extract geo keys from 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 }' }
Опитвам се да вмъкна точка в таблицата с индекс 2dsphere, всички управлявани чрез MongooseJS, както е показано по-долу.
var GeoAddressSchema = new Schema({
// Only holds points.
loc: {
type: { type: String },
coordinates: []
}
});
var Lead = new Schema({
// Other fields ...
location: [GeoAddressSchema],
// ...
});
LeadAddressSchema.index({ location: '2dsphere' });
Geojson, който се запазва:
{ type: "Point", coordinates: [ -111.855211, 33.58513 ] }
Geojson е валиден според: http://geojsonlint.com/, ако увия полетата в кавички, но трябва не е необходимо да правите това (и не може за Mongo afaik).
Някой има ли идея защо това би се провалило? Изглежда правилно.
Връзки за справка
MongoDB GeoJSON: http://docs.mongodb.org/manual/reference/geojson/
MongoDB 2dSphere: http://docs.mongodb.org/manual/core/2dsphere/