On this page本页内容
db.collection.
reIndex
()¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
The db.collection.reIndex()
drops all indexes on a collection and recreates them. db.collection.reIndex()
删除集合上的所有索引并重新创建它们。This operation may be expensive for collections that have a large amount of data and/or a large number of indexes.对于具有大量数据和/或大量索引的集合,此操作可能代价高昂。
Warning
db.collection.reIndex()
operation is unnecessary.db.collection.reIndex()
操作是不必要的。db.collection.reIndex()
against a collection in a replica set.db.collection.reIndex()
。db.collection.reIndex()
against a collection in a sharded cluster.db.collection.reIndex()
。
Changed in version 4.2.在版本4.2中更改。MongoDB disallows MongoDB不允许在db.collection.reIndex()
to be run on a mongos
, implementing a stronger restriction against running db.collection.reIndex()
for a collection in a sharded cluster.mongos
上运行db.collection.reIndex()
,从而对在分片集群中的集合运行db.collection.reIndex()
实施了更严格的限制。
Note
For replica sets, 对于副本集,db.collection.reIndex()
will not propagate from the primary to secondaries. db.collection.reIndex()
不会从primary传播到secondaries。db.collection.reIndex()
will only affect a single mongod
instance.db.collection.reIndex()
将只影响单个mongod
实例。
"4.0"
or earlier, MongoDB will not create an index on a collection if the index entry for an existing document exceeds the Maximum Index Key Length
."4.0"
或更早版本的MongoDB 2.6到MongoDB版本,如果现有文档的索引项超过最大索引键长度,MongoDB将不会在集合上创建索引。Changed in version 4.2.2.在版本4.2.2中更改。
For MongoDB 4.2.2 and later, 对于MongoDB 4.2.2及更高版本,db.collection.reIndex()
obtains an exclusive (W) lock on the collection and blocks other operations on the collection until it completes.db.collection.reIndex()
会获得集合上的独占(W)锁,并阻止对集合的其他操作,直到其完成。
For MongoDB 4.0.0 through 4.2.1, 对于MongoDB 4.0.0到4.2.1,db.collection.reIndex()
obtains a global exclusive (W) lock and blocks other operations on the mongod
until it completes.db.collection.reIndex()
会获得一个全局独占(W)锁,并阻止mongod
上的其他操作,直到它完成。
For MongoDB 3.6 and earlier, these operations 对于MongoDB 3.6及更早版本,这些操作db.collection.reIndex()
obtains an exclusive (W) lock on the database and blocks other operations on the database until finished.db.collection.reIndex()
会获得数据库上的独占(W)锁,并在完成之前阻止数据库上的其他操作。
For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发。
See also参阅