We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fe4506a commit 6d9c125Copy full SHA for 6d9c125
hello_world/script.py
@@ -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