I use MongoDB 3.0 with WiredTiger storage engine. When I checked my Mongo files in dbPath, I saw the names of the files with the formats as below: collection-0--4989330656807016483.wt collection-2--4989330656807016483.wt collection-4--4989330656807016483.wt . . . How can I know the relationship between these file names and real collections' names except the way of data size??
Asked
Active
Viewed 7,263 times
9
-
1Why do you want to know this? – Sergio Tulentsev May 13 '15 at 12:16
3 Answers
6
I have found the way that the command "db.collection.stats()" would show the wiredTiger.metadata.uri which defines the relationship between the collection's logical name and file name the command

tottishi05
- 557
- 1
- 5
- 13
-
Thanks a lot! But how can I identify the index files ? I want backup some test databases with indexes. – user224767 Jan 25 '17 at 08:47
-
2
A simple script to find the collection name for a given file name:
function findInDb(dbName, collectionIdToFind) {
var dbToSearch = db.getSiblingDB(dbName);
var collectionNames = dbToSearch.getCollectionNames();
for(var i = 0; i < collectionNames.length; i++){
var name = collectionNames[i];
var stats = dbToSearch.getCollection(name).stats();
var uri = stats.wiredTiger.uri;
if (uri.endsWith(collectionIdToFind))
return name;
}
return null;
}
function findInAllDbs(collectionIdToFind) {
var adminDb = db.getSiblingDB("admin");
var dbList = adminDb.runCommand({ "listDatabases": 1 }).databases;
for (var i in dbList) {
var found = findInDb(dbList[i].name, collectionIdToFind);
if (found != null) {
return dbList[i].name + "." + found;
}
}
return "(not found)";
}
print(findInAllDbs("collection-20-571885508699163146")); // filename in crash report, etc.

EM0
- 5,369
- 7
- 51
- 85