【问题标题】:Indexing Ref field Mongodb索引 Ref 字段 Mongodb
【发布时间】:2020-07-20 07:55:31
【问题描述】:

我的模型中有这个字段:

author: { type: Schema.Types.ObjectId, ref: 'Author' }

现在我的数据库有超过 20k 的帖子,我想索引这个字段,我尝试从 studio 3t shell 执行这个命令:

db.post.createIndex({ author: 1 });

但是不行,查询还是很慢。

【问题讨论】:

    标签: database mongodb nosql robo3t


    【解决方案1】:

    您可以使用 MongoDB Compass 来create the index 或验证索引是否存在。

    你也可以用它来verify that the index is used in your query

    确定问题是索引未创建(或未正确创建)还是索引存在但未用于您的查询,然后根据需要解决问题。

    【讨论】:

      猜你喜欢
      • 2011-08-28
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 2019-02-23
      相关资源
      最近更新 更多