gpt4 book ai didi

mongodb - 如何将 Geojson 文件导入 MongoDB

转载 作者:IT老高 更新时间:2023-10-28 13:05:34 27 4
gpt4 key购买 nike

由于 Geojson 是实际的 json,我想我可以使用 mongoimport 将数据从 .geojson 文件加载到我的 MongoDB 数据库中。

但我收到以下错误:

exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0

文件大小为 25MB,这是其中的一个片段:

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "node/2661561690",
"properties": {
"timestamp": "2014-02-08T17:58:24Z",
"version": "1",
"changeset": "20451306",
"user": "Schandlers",
"uid": "51690",
"natural": "tree",
"id": "node/2661561690"
},
"geometry": {
"type": "Point",
"coordinates": [
-66.9162255,
10.5056439
]
}
},
// ... Omitted data
{
"type": "Feature",
"id": "node/2664472516",
"properties": {
"timestamp": "2014-02-10T04:27:30Z",
"version": "2",
"changeset": "20477473",
"user": "albertoq",
"uid": "527105",
"name": "Distribuidora Brithijos (Aceites)",
"shop": "car_parts",
"id": "node/2664472516"
},
"geometry": {
"type": "Point",
"coordinates": [
-66.9388903,
10.4833647
]
}
}
]
}

最佳答案

下载jq (它是类似于 sed 的程序,但用于 JSON)

然后运行:

jq --compact-output ".features"input.geojson > output.geojson

然后

mongoimport --db dbname -c collectionname --file "output.geojson"--jsonArray

关于mongodb - 如何将 Geojson 文件导入 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22029114/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com