我试图在我的Meteor应用程序中将GEOJSON Multipolygon对象写入Mongo。
该对象包含几个这样的对象:
var myPolygons = [ {"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[34.826198,32.063821],[34.82618,32.063779],[34.824903,32.063947],[34.820535,32.064516],
...
[34.826329,32.06418],[34.826272,32.064019],[34.826217,32.06387],[34.826198,32.063821]]]]},"properties":{"cartodb_id":12,"category":"someCategory","name":"Some Name"}} ]
上传递(=正确绘制)
在我的数据库中使用find()显示项目已插入,但它们包含null而不是坐标,如下所示:
{ "_id" : "9mraZmupTY5ZRN2BD", "type" : "Feature", "geometry" : { "type" : "MultiPolygon", "coordinates" : [ [ [ null, null, null, null ] ], [ [ null, null, null, null ] ], [ [ null, null, null, null ] ] ] }, "properties" : { "cartodb_id" : 12, "category" : "someCategory", "name" : "Some Name" } }
我使用简单的插页,没什么特别的:
_(myPolygons).each(function (item) {
SomeDB.insert(item);
});
为什么会这样?是否有我不知道的MongoDB嵌套限制?
答案 0 :(得分:1)
我和GeoJSON有类似的问题。问题是我正在从文本文件中复制Multipolygon并尝试创建一个数组。
相反,这对我有用
var state = JSON.parse(Assets.getText('states.txt')); // state.txt is a file in 'private folder' of meteor
// console.log(JSON.stringify(state));
if (State.find({}).count() < 1) { // Checking if
_.each(state.features, function (s) {
console.log(JSON.stringify(s));
var a = new Object();
a.loc = s.geometry; // am storing in LOC so that i can do a geoSpatial Index on this Field
State.insert(a); // State is My Collection
})
}
请注意,此代码正在服务器上运行。 我没有尝试从客户端插入数据。
希望这有帮助