Skip to content

Instantly share code, notes, and snippets.

View cjohnston1158's full-sized avatar

Chris Johnston cjohnston1158

View GitHub Profile
@cjohnston1158
cjohnston1158 / bionic.txt
Last active April 28, 2020 17:06 — forked from niedbalski/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
# for juju on bionic
cat << EOF > /tmp/a.js
db = db.getSiblingDB('juju');
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'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
EOF
/usr/bin/mongo --sslAllowInvalidCertificates --ssl -u admin -p $(grep oldpassword /var/lib/juju/agents/machine-0/agent.conf | awk -e '{print $2}') localhost:37017/admin /tmp/a.js