404 mongodb config_error ai_generated true

MongoServerError:此版本不支持geoHaystack索引

MongoServerError: geoHaystack index is not supported in this version

ID: mongodb/geo-haystack-index-not-supported

其他格式: JSON · Markdown 中文 · English
90%修复率
90%置信度
1证据数
2023-06-01首次发现

版本兼容性

版本状态引入弃用备注
mongodb 7.0 active
mongodb 6.0 active
mongodb 5.0 active

根因分析

geoHaystack索引类型在MongoDB 5.0+中已被弃用并移除,但应用程序仍尝试创建或使用它。

English

The geoHaystack index type was deprecated and removed in MongoDB 5.0+, but the application still tries to create or use it.

generic

官方文档

https://www.mongodb.com/docs/manual/release-notes/5.0-compatibility/#index-removal

解决方案

  1. 用2dsphere索引替换geoHaystack:db.collection.createIndex({ location: '2dsphere' })并使用$nearSphere或$geoWithin查询。
  2. 如果需要边界框查询,使用带有$box的$geoWithin:db.places.find({ location: { $geoWithin: { $box: [ [0,0], [10,10] ] } } })

无效尝试

常见但无效的做法:

  1. 70% 失败

    Downgrading is not recommended and may cause data compatibility issues.

  2. 95% 失败

    No such flag exists; the feature is completely removed.