In this rather lengthy section, we will use the aggregation framework to process data from the Ethereum blockchain.
Using our Python code, we have extracted data from Ethereum and loaded it into our MongoDB database. The relation of the blockchain to our database is shown in the following diagram:
Our data resides in two collections: blocks and transactions.
A sample block document has the following fields:
- Number of transactions
- Number of contracted internal transactions
- Block hash
- Parent block hash
- Mining difficulty
- Gas used
- Block height
The following code shows the output data from a block:
> db.blocks.findOne()
{
"_id" : ObjectId("595368fbcedea89d3f4fb0ca"),
"number_transactions" : 28,
"timestamp" : NumberLong("1498324744877"),
"gas_used" : 4694483,
"number_internal_transactions" : 4...