Advertisement
Guest User

Untitled

a guest
Jul 29th, 2021
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. from pymongo import MongoClient
  2. import pprint
  3. import random
  4. import threading
  5. import string
  6.  
  7. client = MongoClient("localhost")
  8. database = client["test"]
  9. collection = database["inventory"]
  10.  
  11. def get_data():
  12.     resp = []
  13.     for i in range(0,100000):
  14.         name = ''.join(random.sample(string.ascii_letters,23))
  15.         quantity = random.randint(1,1000)
  16.         resp.append({"name":name,"quantity":quantity})
  17.     return resp
  18.  
  19. def save_data():
  20.     collection.insert_many(get_data())
  21.  
  22. for i in range(0,1000):
  23.     print(i)
  24.     save_data()
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement