Fix get_spent mongodb-based query

fixes #1271
This commit is contained in:
Sylvain Bellemare 2017-03-16 13:39:34 +01:00 committed by Sylvain Bellemare
parent b6c21ed819
commit 4f0ba65858

View File

@ -153,14 +153,22 @@ def get_spent(conn, transaction_id, output):
cursor = conn.run( cursor = conn.run(
conn.collection('bigchain').aggregate([ conn.collection('bigchain').aggregate([
{'$match': { {'$match': {
'block.transactions.inputs.fulfills.txid': transaction_id, 'block.transactions.inputs': {
'block.transactions.inputs.fulfills.output': output '$elemMatch': {
'fulfills.txid': transaction_id,
'fulfills.output': output,
},
},
}}, }},
{'$unwind': '$block.transactions'}, {'$unwind': '$block.transactions'},
{'$match': { {'$match': {
'block.transactions.inputs.fulfills.txid': transaction_id, 'block.transactions.inputs': {
'block.transactions.inputs.fulfills.output': output '$elemMatch': {
}} 'fulfills.txid': transaction_id,
'fulfills.output': output,
},
},
}},
])) ]))
# we need to access some nested fields before returning so lets use a # we need to access some nested fields before returning so lets use a
# generator to avoid having to read all records on the cursor at this point # generator to avoid having to read all records on the cursor at this point