gpt4 book ai didi

mongodb - 在 mongodb 中索引正在进行的事件还是我们需要一个 cron?

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

对不起,如果这个问题很愚蠢。我不熟悉数据库的整个索引,想知道我是否发出了以下命令

> db.posts.ensureIndex({location:"2d"})

数据库是否会一直被索引,即使有新的条目被发布?还是我需要在每次输入新条目后输入此命令?

对于包含 2000 多个条目的数据库,索引是否也有很大的不同?

最佳答案

一旦索引就位,它将始终用于任何后续的读取和写入。您无需继续执行命令。

请记住,在现有的大型数据集上发出 ensureIndex 会导致它立即为那里的所有内容编制索引,并且可能会阻塞。

这里有关于索引建议的完整官方常见问题解答:http://www.mongodb.org/display/DOCS/Indexing+Advice+and+FAQ
您应该创建与您正在执行的查询类型相匹配的索引。此外,它非常易于使用 explain 并查看查询需要多长时间。当您发现自己正在一遍又一遍地执行特定类型的查询时,您可以对其进行适当的索引以提高性能。

MongoDB includes an explain command for determining how your queries are being processed and, in particular, whether they're using an index. explain can be used from of the drivers and also from the shell:

db.comments.find({ tags : 'mongodb'}).sort({ created_at : -1
}).explain();

This will return lots of useful information, including the number of items scanned, the time the query takes to process in milliseconds, which indexes the query optimizer tried, and the index ultimately used.

关于mongodb - 在 mongodb 中索引正在进行的事件还是我们需要一个 cron?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11231105/

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