Search
 
SCRIPT & CODE EXAMPLE
 

C

mongo script to find collection size in database

function getReadableFileSizeString(fileSizeInBytes) {

    var i = -1;
    var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
    do {
        fileSizeInBytes = fileSizeInBytes / 1024;
        i++;
    } while (fileSizeInBytes > 1024);

    return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + getReadableFileSizeString(stats[c]['size']) + " (" + getReadableFileSizeString(stats[c]['storageSize']) + ")"); }
Comment

PREVIOUS NEXT
Code Example
C :: print float number completely in C language 
C :: mongodb read 
C :: c change value of const 
C :: calculate median 
C :: passing file as argument in c 
C :: hourglass sum 
C :: sockaddr_in c 
C :: to execute a program using C 
C :: pyinstaller hidden import tensorflow not found 
C :: build a linked list in c 
C :: boolean input in c 
C :: stddef.h 
C :: rust set toolchain 
C :: scan c 
C :: Multi-line Comments in C 
C :: declare and initialize a string in C 
C :: what is console in sublime text 
C :: predefined macros 
C :: gcc compiler for windows 10 
C :: Highest integer among the four inputs in c 
C :: change base int in c 
C :: ask the user if they would like to do something again in C 
C :: c enums 
C :: remove every appearance of char without malloc in c 
C :: Integer Xor swap 
C :: Algorithm that flips sentences and numbers 
C :: c joystick arduino 
C :: lognormal distribution - matlab 
C :: reap zombie process in c 
C :: online c compiler with mpi 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =