Created On: February 15, 2022, Last Updated On: February 15, 2022
By Ozzie Ghani3 new
Create db
from pymongo import MongoClient, errors
DOMAIN = "143.198.246.63"
PORT = 6902
USER = "mongouser"
PASS = "quizMongo_94646_LaHore_01"
DB = "restcust"
AUTHSOURCE = "admin"
def connect():
try:
uri = f"mongodb://{USER}:{PASS}@{DOMAIN}:{PORT}/{DB}?authSource={AUTHSOURCE}"
client = MongoClient(uri, serverSelectionTimeoutMS = 3000)
except errors.ServerSelectionTimeoutError as err:
client = None
print ("pymongo ERROR:", err)
return client
client = connect()
db = client.test_pegination
col = db.peg_example
for i in range(100):
col.insert_one({"transaction_id": 123 + i})
DB looks like following