Add MongoDB skill to skills folder and update skill index
This commit is contained in:
parent
dc26b7fb40
commit
e487b28c44
3 changed files with 158 additions and 0 deletions
33
mongodb/scripts/connect.py
Normal file
33
mongodb/scripts/connect.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from pymongo import MongoClient
|
||||
|
||||
MONGODB_URI = "mongodb://root:3wwfoUjyk2E2zWELXFlLuHqfw1ALlOp4pb2H5Vq3TImbMIHL2h1u8Jej2mjzCPl@docdb.connorrhodes.com:35563"
|
||||
|
||||
|
||||
def get_client():
|
||||
return MongoClient(MONGODB_URI)
|
||||
|
||||
|
||||
def get_db(db_name):
|
||||
return MongoClient(MONGODB_URI)[db_name]
|
||||
|
||||
|
||||
def get_collection(db_name, collection_name):
|
||||
return MongoClient(MONGODB_URI)[db_name][collection_name]
|
||||
|
||||
|
||||
def list_databases():
|
||||
client = get_client()
|
||||
for db_name in client.list_database_names():
|
||||
db = client[db_name]
|
||||
collections = []
|
||||
for coll_name in db.list_collection_names():
|
||||
count = db[coll_name].estimated_document_count()
|
||||
collections.append(f"{coll_name} ({count} docs)")
|
||||
print(f"Database: {db_name}")
|
||||
for c in collections:
|
||||
print(f" {c}")
|
||||
client.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
list_databases()
|
||||
Loading…
Add table
Add a link
Reference in a new issue