Skip to content

Instantly share code, notes, and snippets.

@nnn-gif
Created December 5, 2018 10:09
Show Gist options
  • Save nnn-gif/ff5b12a26efda8f05fe8d841bd270c12 to your computer and use it in GitHub Desktop.
Save nnn-gif/ff5b12a26efda8f05fe8d841bd270c12 to your computer and use it in GitHub Desktop.
db.createView('uncles', 'blocks', [
{ $sort: { _id: -1 } },
{ $unwind: { path: '$uncles', includeArrayIndex: "position" } },
{ $project: { hash: 1, number: 1, timestamp: '$header.timestamp', index: 1, uncle: '$uncles' ,blockNumber:1} },
{
$addFields: {
'uncle.timestamp': '$timestamp',
'uncle.index': '$index',
'uncle.blockNumber': '$index',
'uncle.position':'$position'
}
},
{
$project: {
parentHash: '$uncle.parentHash',
blockNumber: '$uncle.blockNumber',
position: '$uncle.position',
sha3Uncles: '$uncle.sha3Uncles',
hash: '$uncle.hash',
timestamp: '$uncle.timestamp',
nonce: '$uncle.nonce',
miner: '$uncle.miner',
rewards: '$uncle.rewards',
difficulty: '$uncle.difficulty',
totalDifficulty: '$uncle.totalDifficulty',
stateRoot: '$uncle.stateRoot',
transactionsRoot: '$uncle.transactionsRoot',
receiptsRoot: '$uncle.receiptsRoot',
logsBloom: '$uncle.logsBloom',
gasLimit: '$uncle.gasLimit',
gasUsed: '$uncle.gasUsed',
mixHash: '$uncle.mixHash',
extraData: '$uncle.extraData'
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment