File size: 697 Bytes
a01f0a1 |
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 |
import pymongo
# Provide the mongodb localhost url to connect python to mongodb.
client = pymongo.MongoClient("mongodb://localhost:27020/neurolabDB")
# Database Name
dataBase = client["neurolabDB"]
# Collection Name
collection = dataBase['Products']
# Sample data
d = {'companyName': 'iNeuron',
'product': 'Affordable AI',
'courseOffered': 'Machine Learning with Deployment'}
# Insert above records in the collection
rec = collection.insert_one(d)
# Lets Verify all the record at once present in the record with all the fields
all_record = collection.find()
# Printing all records present in the collection
for idx, record in enumerate(all_record):
print(f"{idx}: {record}") |