This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
forked from bigchaindb/coalaip-http-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
|
||
from pymongo import MongoClient | ||
|
||
def bdb(): | ||
return MongoClient(os.environ.get('MONGODB_HOST', None), | ||
int(os.environ.get('MONGODB_PORT', None)), | ||
ssl=False) | ||
|
||
def bdb_coll(): | ||
return bdb()['bigchain']['bigchain'] | ||
|
||
def bdb_find(query, _type): | ||
# TODO: make this a global? | ||
base = 'block.transactions.asset.data' | ||
|
||
match = [] | ||
for key, value in query.items(): | ||
# Filter out None values | ||
if value: | ||
match.append({'{}.{}'.format(base, key): value}) | ||
match.append({'{}.@type'.format(base): _type}) | ||
match = {'$and': match} | ||
|
||
pipeline = [ | ||
{'$match': match}, | ||
{'$unwind': '$block.transactions'}, | ||
{'$match': match}, | ||
{'$project': { | ||
'_id': False, | ||
'block.transactions.asset.data': True | ||
}} | ||
] | ||
|
||
cur = bdb_coll().aggregate(pipeline) | ||
return cur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters