from pymongo import MongoClient c = MongoClient("mongodb://localhost:27017/") db = c['grpDB'] col = db['sales'] data = [ {"_id": 1, "user": "Amit", "product": "Pen", "amount": 5}, {"_id": 2, "user": "Drew", "product": "Pencil", "amount": 3}, {"_id": 3, "user": "Amit", "product": "Notebook", "amount": 15}, {"_id": 4, "user": "Cody", "product": "Pen", "amount": 7}, {"_id": 5, "user": "Drew", "product": "Notebook", "amount": 12}, {"_id": 6, "user": "Cody", "product": "Eraser", "amount": 2}, {"_id": 7, "user": "Amit", "product": "Pen", "amount": 10} ] col.delete_many({}) col.insert_many(data) print("Data inserted.")