I have more than 600 databases in my MongoDB system. Whenever i run command show dbs it returns databases with their sizes in alphabetical order. I want to get databases in Ascending or Descending order.
Is that possible in MongoDB ?
You can write simple java scripts inside shell
db.adminCommand("listDatabases").databases
.sort(function(l, r) {
return r.sizeOnDisk - l.sizeOnDisk})
.forEach(function(d) {
print(d.name + " - " + d.sizeOnDisk)});
Or invoke shell with passing the script:
mongo --quiet --eval 'db.adminCommand("listDatabases").databases.sort(function(l, r) {return r.sizeOnDisk - l.sizeOnDisk}).forEach(function(d) {print(d.name + " - " + d.sizeOnDisk)});'
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