Wrap queries with connection object

This commit is contained in:
vrde 2017-02-06 14:43:40 +01:00
parent 01da32d351
commit 3c45de70d0
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D

View File

@ -121,7 +121,9 @@ def get_txids_filtered(conn, asset_id, operation=None):
{'$match': match},
{'$project': {'block.transactions.id': True}}
]
cursor = conn.db['bigchain'].aggregate(pipeline)
cursor = conn.run(
conn.collection('bigchain')
.aggregate(pipeline))
return (elem['block']['transactions']['id'] for elem in cursor)
@ -281,18 +283,20 @@ def get_last_voted_block(conn, node_pubkey):
@register_query(MongoDBConnection)
def get_unvoted_blocks(conn, node_pubkey):
return conn.db['bigchain'].aggregate([
{'$lookup': {
'from': 'votes',
'localField': 'id',
'foreignField': 'vote.voting_for_block',
'as': 'votes'
}},
{'$match': {
'votes.node_pubkey': {'$ne': node_pubkey},
'block.transactions.operation': {'$ne': 'GENESIS'}
}},
{'$project': {
'votes': False, '_id': False
}}
])
return conn.run(
conn.collection('bigchain')
.aggregate([
{'$lookup': {
'from': 'votes',
'localField': 'id',
'foreignField': 'vote.voting_for_block',
'as': 'votes'
}},
{'$match': {
'votes.node_pubkey': {'$ne': node_pubkey},
'block.transactions.operation': {'$ne': 'GENESIS'}
}},
{'$project': {
'votes': False, '_id': False
}}
]))