Lista indeksów w MongoDB?
Czy jest sposób, aby zobaczyć listę indeksów na kolekcji w mongodb w powłoce? przeczytałem http://www.mongodb.org/display/DOCS/Indexes but I dont see anything
6 answers
Z powłoki:
db.test.getIndexes()
Aby uzyskać pomoc shell należy spróbować:
help;
db.help();
db.test.help();
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-07 22:52:22
A jeśli chcesz uzyskać listę wszystkich indeksów w swojej bazie danych:
use "yourdbname"
db.system.indexes.find()
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-20 21:59:19
Upewnij się, że używasz swojej kolekcji:
db.collection.getIndexes()
Http://docs.mongodb.org/manual/administration/indexes/#information-about-indexes
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-13 12:43:49
Możesz również wypisać wszystkie indeksy wraz z ich rozmiarem:
db.collectionName.stats().indexSizes
Sprawdź również, czy db.collectionName.stats()
daje Ci wiele ciekawych informacji, takich jak paddingFactor, rozmiar kolekcji i ilość elementów w niej zawartych.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-31 05:41:19
Jeśli chcesz wyświetlić listę wszystkich indeksów:
db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-26 15:26:38
Idąc o krok dalej, jeśli chcesz znaleźć wszystkie indeksy we wszystkich kolekcjach, ten skrypt (zmodyfikowany na podstawie skryptu Juana Carlosa Faraha Tutaj) daje Ci kilka przydatnych wyników, w tym Wydruk JSON szczegółów indeksu:
// Switch to admin database and get list of databases.
db = db.getSiblingDB("admin");
dbs = db.runCommand({ "listDatabases": 1}).databases;
// Iterate through each database and get its collections.
dbs.forEach(function(database) {
db = db.getSiblingDB(database.name);
cols = db.getCollectionNames();
// Iterate through each collection.
cols.forEach(function(col) {
//Find all indexes for each collection
indexes = db[col].getIndexes();
indexes.forEach(function(idx) {
print("Database:" + database.name + " | Collection:" +col+ " | Index:" + idx.name);
printjson(indexes);
});
});
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:54:28