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}, {'$match': match},
{'$project': {'block.transactions.id': True}} {'$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) return (elem['block']['transactions']['id'] for elem in cursor)
@ -281,7 +283,9 @@ def get_last_voted_block(conn, node_pubkey):
@register_query(MongoDBConnection) @register_query(MongoDBConnection)
def get_unvoted_blocks(conn, node_pubkey): def get_unvoted_blocks(conn, node_pubkey):
return conn.db['bigchain'].aggregate([ return conn.run(
conn.collection('bigchain')
.aggregate([
{'$lookup': { {'$lookup': {
'from': 'votes', 'from': 'votes',
'localField': 'id', 'localField': 'id',
@ -295,4 +299,4 @@ def get_unvoted_blocks(conn, node_pubkey):
{'$project': { {'$project': {
'votes': False, '_id': False 'votes': False, '_id': False
}} }}
]) ]))