Skip to content

Commit

Permalink
return hello_world
Browse files Browse the repository at this point in the history
  • Loading branch information
mSulimenko committed Dec 8, 2024
1 parent c846b65 commit e18d08b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hello_world/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.1'

services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
ports:
- 27017:27017

mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: 'mongodb://root:example@mongo:27017/'
ME_CONFIG_BASICAUTH: false
39 changes: 39 additions & 0 deletions hello_world/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
import pprint
import pymongo

class Connection:
def __init__(self, host='localhost', port=27017, username='root', password=''):
self.host = host
self.port = port
self.username = username
self.password = password

def connect(self):
uri = f'mongodb://{self.username}:{self.password}@{self.host}:{self.port}/'
return pymongo.MongoClient(uri)

def main():
database_name = "db_test"
collection_name = "test"

connection = Connection(password='example').connect()
database = connection[database_name]
collection = database[collection_name]
collection.drop()

while True:
data = input('Input some shite:\n')
if data == '':
break
print(collection.find_one({"_id": collection.insert_one({ 'input' : data }).inserted_id})['input'])

print('\nThat\'s what we have here:')
for post in collection.find():
pprint.pprint(post)

connection.close()


if __name__ == '__main__':
main()

0 comments on commit e18d08b

Please sign in to comment.