Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from pymongo import MongoClient
- client = MongoClient('localhost',
- 18890,
- username='your_user_name',
- password='your_password',
- authSource='events')
- db = client.events
- hour_in_milliseconds = 3600000
- print('Database: ', db.name)
- try:
- collection = db.eventLog
- print('Collection: ', collection)
- num = collection.find().count()
- now = time.time()
- cut_off = int(round(now * 1000)) - (5 * hour_in_milliseconds)
- query = {'$or': [
- {'resource_Node': 'SolidityNode'},
- {'block_timestamp': {'$lt': cut_off}}
- ]}
- if int(num) >= 3000000:
- x = collection.delete_many(query)
- print(x.deleted_count, ' removed')
- else:
- print('ok ', num)
- except Exception as e:
- print e
Add Comment
Please, Sign In to add comment