gpt4 book ai didi

mongodb - MongoDB 索引是否在重新启动后保持不变?

转载 作者:可可西里 更新时间:2023-11-01 09:32:01 25 4
gpt4 key购买 nike

在这里引用指南,http://docs.mongodb.org/manual/core/indexes/我不知道字段的 Mongo 索引是否持久存储。

如果在使用 MongoDB 的应用程序中调用(并完成)ensureIndex(),如果出现以下情况会发生什么情况:

  1. 使用 MongoDB 的应用程序重新启动。对 ensureIndex() 的后续调用是否会导致完整的重建索引?
  2. MongoDB 服务器重新启动。稍后从客户端应用程序调用 ensureIndex() 会重建吗?
  3. 这是否会受到多个客户 session 的影响?根据文档,我假设索引在整个集合中是全局的:“MongoDB 在每个集合级别定义索引。”

最佳答案

The application using MongoDB is restarted. Will a subsequent call to ensureIndex() cause a complete reindex?

不,它应该(在所有其他驱动程序中)注册为 no op,因为索引已经存在。一些驱动程序提供了一种缓存机制,无需访问服务器即可检测是否已创建索引(即 Python)。

The MongoDB server is restarted. Would a later call of ensureIndex() from a client application rebuild?

同上

Is any of this affected by having multiple client sessions? I assume indexing is global across the entire collection per the documentation: "MongoDB defines indexes on a per-collection level."

是的,索引存储在集合本身的 MongoDB 中(技术上,作为 db.ns 文件中的命名空间)。由于它是 ensureIndex 的单一知识点,并且索引是单个进程(很像真正的写锁),因此多个连接不应影响索引创建是否被注册两次。

关于mongodb - MongoDB 索引是否在重新启动后保持不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14333331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com