-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmongotests.py
More file actions
27 lines (21 loc) · 819 Bytes
/
mongotests.py
File metadata and controls
27 lines (21 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pymongo import MongoClient
client = MongoClient()
db = client.exploder
# db.blocks.aggregate(
# {"$group" : { "_id": "$blockhash", "count": { "$sum": 1 } } },
# {"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
# {"$project": {"blockhash" : "$_id", "_id" : 0} }
# )
# There should be no duplicate blockhashes
pipeline = [
{"$group": {"_id": "$blockhash", "count": {"$sum": 1}}},
{"$match": {"_id" :{ "$ne" : None } , "count" : {"$gt": 1} } },
{"$project": {"blockhash": "$_id", "_id": 0}}
]
assert len(list(db.blocks.aggregate(pipeline))) == 0
# There should be no duplicate txids
pipeline = [
{"$group": {"_id": "$txid", "count": {"$sum": 1}}},
{"$match": {"_id" :{ "$ne" : None } , "count" : {"$gt": 1} } },
{"$project": {"blockhash": "$_id", "_id": 0}}
]