Skip to content

Commit 6d9c125

Browse files
committed
First iteration
1 parent fe4506a commit 6d9c125

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

hello_world/script.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pymongo import MongoClient
2+
3+
client = MongoClient('mongodb://admin:admin@localhost:27017/',authSource='admin')
4+
5+
db = client['mydatabase']
6+
7+
collection = db['mycollection']
8+
9+
document = {'name': "Alisa", 'age':20, 'city': "SPb"}
10+
insert_result = collection.insert_one(document)
11+
12+
print(f'Вставленный ID: {insert_result.inserted_id}')
13+
14+
query = {'name': 'Alisa'}
15+
found_document = collection.find_one(query)
16+
print(f'Найденный документ: {found_document}')
17+
18+
update_query = {'name': "Alisa"}
19+
new_values = {'$set': {'age':19}}
20+
collection.update_one(update_query, new_values)
21+
print("Документ обновлен")
22+

0 commit comments

Comments
 (0)