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??
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
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.
Use this
db.getCollection('collection_name').stats()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With