多个2d索引,不确定运行geoNear的是哪个 [英] more than one 2d index, not sure which to run geoNear on

查看:99
本文介绍了多个2d索引,不确定运行geoNear的是哪个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么聚合

    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
}

在计划中有唯一的2d指数:

having in the scheme the only 2d index:

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

或多或少当我从方案中删除一切时,错误会改变
为什么? o为什么......

more or less when i remove EVERYTHING from the scheme the error doenst change why? o why...

推荐答案

当您删除Mongoose模型中的索引(甚至整个字段)时,它是 not 自动从MongoDB中删除。

When you remove an index (or even an entire field) in your Mongoose model, it is not automatically removed from MongoDB.

运行 db。<您的集合名称> .getIndexes()查看所有索引。记下要删除的索引的名称

Run db.<your collection name>.getIndexes() to view all indexes. Make a note of the name of the index you want to remove.

运行 db。<您的集合名称> .dropIndex(<索引的名称>)要删除一个索引。

默认情况下,Mongoose告诉MongoDB(重新)创建索引( ensureIndex() )当你启动你的应用程序时。

By default, Mongoose tells MongoDB to (re-)create indexes ("ensureIndex()") when you start your app.

这篇关于多个2d索引,不确定运行geoNear的是哪个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆