Guest User

Untitled

a guest
Nov 28th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import time
  2. from pymongo import MongoClient
  3.  
  4. client = MongoClient('localhost',
  5. 18890,
  6. username='your_user_name',
  7. password='your_password',
  8. authSource='events')
  9. db = client.events
  10.  
  11. hour_in_milliseconds = 3600000
  12.  
  13. print('Database: ', db.name)
  14.  
  15. try:
  16. collection = db.eventLog
  17. print('Collection: ', collection)
  18. num = collection.find().count()
  19. now = time.time()
  20. cut_off = int(round(now * 1000)) - (5 * hour_in_milliseconds)
  21. query = {'$or': [
  22. {'resource_Node': 'SolidityNode'},
  23. {'block_timestamp': {'$lt': cut_off}}
  24. ]}
  25. if int(num) >= 3000000:
  26. x = collection.delete_many(query)
  27. print(x.deleted_count, ' removed')
  28. else:
  29. print('ok ', num)
  30.  
  31. except Exception as e:
  32. print e
Add Comment
Please, Sign In to add comment