From 9fbdc7d9b9537d769447c4da23141c7cbfeaebb1 Mon Sep 17 00:00:00 2001 From: srezal Date: Mon, 10 Mar 2025 07:57:10 +0300 Subject: [PATCH] added hello_world folder with db+pl demonstaration --- hello_world/main.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 hello_world/main.py diff --git a/hello_world/main.py b/hello_world/main.py new file mode 100644 index 0000000..3a53510 --- /dev/null +++ b/hello_world/main.py @@ -0,0 +1,34 @@ +from pymongo import MongoClient +import datetime +import os +from dotenv import load_dotenv + + +load_dotenv('../.env') + + +db_uri = f'mongodb://{os.environ['MONGO_INITDB_ROOT_USERNAME']}:{os.environ['MONGO_INITDB_ROOT_PASSWORD']}@{os.environ['MONGO_DB_HOST']}:{os.environ['MONGO_DB_PORT']}/' +client = MongoClient(db_uri) + +print('Cписок доступных БД по умолчанию:') +print(client.list_database_names()) +print('') + + +gdwrapper_db = client['gdwrapper_db'] +collection = gdwrapper_db['test_collection'] +collection.insert_one( + { + 'Info': 'This is test data', + 'Timestamp': datetime.datetime.now(tz=datetime.timezone.utc) + } +) + +print('Cписок доступных БД после добавления gdwrapper_db:') +print(client.list_database_names()) +print('') + + +print('Данные gdwrapper_db из коллекции test_collection:') +for item in client.get_database('gdwrapper_db').get_collection('test_collection').find(): + print(item)