Skip to content

Instantly share code, notes, and snippets.

@dubeyji10
Created July 19, 2022 11:44
Show Gist options
  • Save dubeyji10/ae074b6396267e327de0281271d9644f to your computer and use it in GitHub Desktop.
Save dubeyji10/ae074b6396267e327de0281271d9644f to your computer and use it in GitHub Desktop.
Connection to local mongodb instance for test
from pprint import pprint
from pymongo import MongoClient
#mongodb://127.0.0.1:27017/
client = MongoClient(host="localhost", port=27017)
print("1.connected to mongodb")
db = client.landTest
print("2.db : ",db)
# print("")
collection = db.landTest
print("\n\n3.collection:",collection)
client.close()
print("4.documents : \n")
for doc in collection.find():
pprint(doc)
print('-----------------')
print("\n\n--connection closed--")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment