我正在尝试在 MongoDB 中为一个LineString
对象构建一个索引,该对象具有一个名为坐标的数组,该数组包含两个或多个坐标对数组。
当我运行时,db.infrastructure.createIndex({ "geometry.coordinates": "2dsphere" })
我收到以下错误:
MongoServerError: Index build failed: 9ceb3eaa-ff36-48bd-a0a6-cffbc42dcc7a: Collection energy_maps_local_db.infrastructure ( 38a51548-49ea-4ad6-8c90-0cc76e3a1ae7 ) :: caused by :: Can't extract geo keys: { _id: ObjectId('611d22b7bdcefb8992c3f91c'), type: "Feature", properties: { original: { FNODE_: 57, TNODE_: 58, LENGTH: 0.00701013, RAILRDL020: 56, RROWNER1: "Burlington Northern and Santa Fe Railway Company", RROWNER2: null, RROWNER3: null, MARK1: "BNSF", MARK2: null, MARK3: null }, required: { unit: null, viz_dim: null, years: [] }, optional: { description: "" }, type: { primary: "railroads", secondary: null } }, geometry: { type: "LineString", coordinates: [ [ -122.2382307661753, 47.30122202419908 ], [ -122.2312344168241, 47.30166453943731 ] ] } } Point must only contain numeric elements
它说该点必须只包含数字元素,所以我假设它与数组数组有关。
我会尝试使用多索引键,但您似乎无法为多索引createIndex()
操作指定 2dsphere。如果可能的话,我想避免修改我的数据。