Aggregation use case
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 relationship of the blockchain to our database is shown in the following diagram:
Figure 7.1: A MongoDB database interacting with the Ethereum public blockchain
Our data resides in two collections: blocks and transactions.
A sample block document has the following fields:
- The number of transactions
- The number of contracted internal transactions
- The block hash
- The parent block hash
- The mining difficulty
- The amount of gas used
- The block height
The following code shows the output data from a block:
> db.blocks.findOne()
{
"_id" : ObjectId("595368fbcedea89d3f4fb0ca"),
"number_transactions" : 28,
"timestamp" : NumberLong("...