用于重新索引所有mongodb集合的命令 [英] Command to reindex all mongodb collections

查看:92
本文介绍了用于重新索引所有mongodb集合的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重新索引MongoDB集合的引用通常是每个集合:

References to reindexing MongoDB collections are usually per collection:

db.mycollection.reIndex();

我想一次重新索引一些收藏品。一个接一个可能会有点累人。

I'd like to reindex a number of collections all at once. One-by-one can get a bit tiring.

发出 reIndex(); 的适当命令是什么所有系列?

What's the appropriate command to issue reIndex(); across all collections?

推荐答案

这个怎么样?它仍然是数据库的一个一个,但只有一个命令。

What about this? It's still one-by-one for the database, but just one command for you.

db.getCollectionNames().forEach(function(coll_name) {
  var coll = db.getCollection(coll_name);
  coll.reIndex();
});

这篇关于用于重新索引所有mongodb集合的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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