kao*_*ify 5 geometry mongodb 2dsphere
当我尝试创建几何的索引db.polygons.createIndex({"geometry":"2dsphere"}),它停止在错误代码16755.它说,它有一定的多边形Can't extract geo keys和Duplicate vertices: 18 and 20。
因此,在进一步检查时,当多边形中的2个节点彼此靠近甚至重复时,似乎会发生这种情况。
然后,我手动在QGIS中删除此节点,然后重试该过程,却发现存在另一个存在相同问题的多边形。
如何解决此问题,而不必重复整个固定多边形的过程>上传到MongoDB>创建索引?有没有办法找出这个问题有多少个多边形?
我遇到了类似的问题。我只需要在数据集中找到有效记录(我就用重复顶点丢弃了记录)。
我重命名了收藏集-
db.myCollection.renameCollection('myCollectionBk')
Run Code Online (Sandbox Code Playgroud)
然后,我将原始集合中的一条记录添加到新集合中,并向该集合中添加了地理空间索引
db.myCollection.insert(db.myCollectionBk.findOne()) // recreate the collection
db.myCollection.createIndex({geometry:"2dsphere"}) // create the index (assumes the geometry on the record is valid)
db.myCollection.remove({}) // remove the record
Run Code Online (Sandbox Code Playgroud)
然后,我将有效记录添加到新集合中。
db.myCollectionBk.find().forEach(function(x){
db.myCollection.insert(x);
})
Run Code Online (Sandbox Code Playgroud)
无效的记录将被忽略。
在您的情况下,您可能想从insert那里获取WriteResult,然后看看它是否成功。就像是
var errors = []
db.myCollectionBk.find().forEach(function(x){
var result = db.myCollection.insert(x);
if (result.writeError) {
errors.push({x._id:result.writeError.errmsg});
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3895 次 |
| 最近记录: |