Learning about Blockchain explorer Mongodb

13 Likes Comment
  1. Setup a crypto coin blockchain explorer: I deployed a iquidus explorer.
  2. Remember some useful sql for Mongodb:

#startup

sudo service mongod start

# connect console commands

#mongo

> show dbs;

> use tempdb;

> db.dropDatabase();
{ “dropped” : “tempdb”, “ok” : 1 }

List 100 richest holders:

db.addresses.aggregate([{ $group: { _id: “$a_id”, total: { $sum: “$balance” } } },{ $sort: { total: -1 } },{ $limit : 100 }]);

      Total current supply coins:

/ext/getmoneysupply
2541450840.4215493
coin-cli gettxoutsetinfo
“total_amount”: 3286598798.90982342

Backup mongodb:

mongodump -d database-name -o folder-to-store-backup-db-files

Restore mongodb

mongorestore -d database-name folder-to-store-backup-db-files

Display the last record in a collection of a mongo database:

db.collection.find().limit(1).sort({$natural:-1})

List all databases with collections size in mongodb server:

mongo --eval " db.getMongo().getDBNames().forEach( function(v, i){ db.getSiblingDB(v).getCollectionNames().forEach( function(vv, ii){ print (v + ',' + vv + ',' + db.getSiblingDB(v).getCollection(vv).count() ) } ) } ) "

Backup & restore mongodb database:https://stackoverflow.com/questions/11255630/how-to-export-all-collections-in-mongodb

You might like

About the Author: Toc Xoan

This guy likes taking photos, hunting cheap tours, exploring the unique culture of every cities of Vietnam. Contact: [email protected]