有多个2D索引,不确定应该在哪一个上运行geoNear。

4

为什么要进行聚合

    aggregate.near({
      near: coord,
      distanceField: "distance",
      maxDistance: max
    });

可以返回

{
    "name": "MongoError",
    "errmsg": "exception: geoNear command failed: { ok: 0.0, errmsg: \"more than one 2d index, not sure which to run geoNear on\" }",
    "code": 16604,
    "ok": 0
}

在这个方案中,只有一个二维索引:

location: { type: [ Number ], index: '2d', sparse: true },

当我从方案中删除 EVERYTHING 时,错误没有改变。

为什么?哦,为什么...
1个回答

8
当您在Mongoose模型中删除索引(甚至整个字段)时,它不会自动从MongoDB中删除。运行 db.<您的集合名称>.getIndexes()查看所有索引。记录您想要删除的索引的name。可运行 db.<您的集合名称>.dropIndex(<索引名称>)来删除索引。默认情况下,当您启动应用程序时,Mongoose会告诉MongoDB重新创建索引"ensureIndex()"。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接