Spaces:
Running
Running
add time
Browse files- db/mongodb.py +3 -1
- test.ipynb +106 -24
db/mongodb.py
CHANGED
|
@@ -4,6 +4,7 @@ from bson import ObjectId
|
|
| 4 |
import os
|
| 5 |
from io import BytesIO
|
| 6 |
import magic
|
|
|
|
| 7 |
|
| 8 |
def connect_mongodb(db_name, collection_name):
|
| 9 |
client = MongoClient("mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0")
|
|
@@ -36,7 +37,8 @@ def save_file_to_mongodb(uploaded_file, db_name="pptx", collection_name="root_fi
|
|
| 36 |
|
| 37 |
# Sau khi dọn dẹp (nếu cần), tiến hành lưu
|
| 38 |
file_id = fs.put(file_bytes, filename=file_name)
|
| 39 |
-
|
|
|
|
| 40 |
return file_id, file_name
|
| 41 |
|
| 42 |
except Exception as e:
|
|
|
|
| 4 |
import os
|
| 5 |
from io import BytesIO
|
| 6 |
import magic
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
def connect_mongodb(db_name, collection_name):
|
| 10 |
client = MongoClient("mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0")
|
|
|
|
| 37 |
|
| 38 |
# Sau khi dọn dẹp (nếu cần), tiến hành lưu
|
| 39 |
file_id = fs.put(file_bytes, filename=file_name)
|
| 40 |
+
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
| 41 |
+
print(f"{now: } File '{file_name}' đã được lưu vào '{collection_name}' với ID: {file_id}")
|
| 42 |
return file_id, file_name
|
| 43 |
|
| 44 |
except Exception as e:
|
test.ipynb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [],
|
| 8 |
"source": [
|
|
@@ -30,17 +30,11 @@
|
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
-
"execution_count":
|
| 34 |
"metadata": {},
|
| 35 |
"outputs": [],
|
| 36 |
"source": [
|
| 37 |
"def delete_all_files_in_collection(collection_name, db_name=\"ppt\"):\n",
|
| 38 |
-
" \"\"\"\n",
|
| 39 |
-
" Xóa toàn bộ file trong GridFS của MongoDB.\n",
|
| 40 |
-
"\n",
|
| 41 |
-
" :param collection_name: Tên collection chứa file cần xoá (ví dụ: 'original_pptx', 'original_xml', 'final_xml')\n",
|
| 42 |
-
" :param db_name: Tên database MongoDB (mặc định: 'ppt')\n",
|
| 43 |
-
" \"\"\"\n",
|
| 44 |
" try:\n",
|
| 45 |
" # Kết nối MongoDB\n",
|
| 46 |
" client = MongoClient(\"mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0\")\n",
|
|
@@ -56,7 +50,7 @@
|
|
| 56 |
" for file_id in file_ids:\n",
|
| 57 |
" fs.delete(file_id)\n",
|
| 58 |
"\n",
|
| 59 |
-
" print(f\"✅ Đã xóa {len(file_ids)} file trong collection '{collection_name}'\")\n",
|
| 60 |
"\n",
|
| 61 |
" except Exception as e:\n",
|
| 62 |
" print(f\"❌ Lỗi khi xóa file: {str(e)}\")\n",
|
|
@@ -84,7 +78,7 @@
|
|
| 84 |
},
|
| 85 |
{
|
| 86 |
"cell_type": "code",
|
| 87 |
-
"execution_count":
|
| 88 |
"metadata": {},
|
| 89 |
"outputs": [],
|
| 90 |
"source": [
|
|
@@ -125,7 +119,7 @@
|
|
| 125 |
},
|
| 126 |
{
|
| 127 |
"cell_type": "code",
|
| 128 |
-
"execution_count":
|
| 129 |
"metadata": {},
|
| 130 |
"outputs": [],
|
| 131 |
"source": [
|
|
@@ -156,7 +150,7 @@
|
|
| 156 |
},
|
| 157 |
{
|
| 158 |
"cell_type": "code",
|
| 159 |
-
"execution_count":
|
| 160 |
"metadata": {},
|
| 161 |
"outputs": [],
|
| 162 |
"source": [
|
|
@@ -187,36 +181,36 @@
|
|
| 187 |
},
|
| 188 |
{
|
| 189 |
"cell_type": "code",
|
| 190 |
-
"execution_count":
|
| 191 |
"metadata": {},
|
| 192 |
"outputs": [
|
| 193 |
{
|
| 194 |
"name": "stdout",
|
| 195 |
"output_type": "stream",
|
| 196 |
"text": [
|
| 197 |
-
"✅ File đã được tải về: D:\\Show_me_everything\\Machine Translation\\input\\
|
| 198 |
]
|
| 199 |
}
|
| 200 |
],
|
| 201 |
"source": [
|
| 202 |
-
"download_input_from_mongodb(file_id=\"
|
| 203 |
]
|
| 204 |
},
|
| 205 |
{
|
| 206 |
"cell_type": "code",
|
| 207 |
-
"execution_count":
|
| 208 |
"metadata": {},
|
| 209 |
"outputs": [
|
| 210 |
{
|
| 211 |
"name": "stdout",
|
| 212 |
"output_type": "stream",
|
| 213 |
"text": [
|
| 214 |
-
"✅ File đã được tải về: D:\\Show_me_everything\\Machine Translation\\output\\
|
| 215 |
]
|
| 216 |
}
|
| 217 |
],
|
| 218 |
"source": [
|
| 219 |
-
"download_output_from_mongodb(file_id=\"
|
| 220 |
]
|
| 221 |
},
|
| 222 |
{
|
|
@@ -228,14 +222,14 @@
|
|
| 228 |
},
|
| 229 |
{
|
| 230 |
"cell_type": "code",
|
| 231 |
-
"execution_count":
|
| 232 |
"metadata": {},
|
| 233 |
"outputs": [
|
| 234 |
{
|
| 235 |
"name": "stdout",
|
| 236 |
"output_type": "stream",
|
| 237 |
"text": [
|
| 238 |
-
"✅ Đã xóa
|
| 239 |
"✅ Đã xóa 0 file trong collection 'final_pptx'\n",
|
| 240 |
"✅ Đã xóa 0 file trong collection 'original_xml'\n",
|
| 241 |
"✅ Đã xóa 0 file trong collection 'final_xml'\n"
|
|
@@ -250,21 +244,109 @@
|
|
| 250 |
},
|
| 251 |
{
|
| 252 |
"cell_type": "code",
|
| 253 |
-
"execution_count":
|
| 254 |
"metadata": {},
|
| 255 |
"outputs": [
|
| 256 |
{
|
| 257 |
"name": "stdout",
|
| 258 |
"output_type": "stream",
|
| 259 |
"text": [
|
| 260 |
-
"✅ Đã xóa
|
| 261 |
-
"✅ Đã xóa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
]
|
| 263 |
}
|
| 264 |
],
|
| 265 |
"source": [
|
| 266 |
"for i in ['root_file', 'final_file']:\n",
|
| 267 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
]
|
| 269 |
},
|
| 270 |
{
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [],
|
| 8 |
"source": [
|
|
|
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
+
"execution_count": 5,
|
| 34 |
"metadata": {},
|
| 35 |
"outputs": [],
|
| 36 |
"source": [
|
| 37 |
"def delete_all_files_in_collection(collection_name, db_name=\"ppt\"):\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
" try:\n",
|
| 39 |
" # Kết nối MongoDB\n",
|
| 40 |
" client = MongoClient(\"mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0\")\n",
|
|
|
|
| 50 |
" for file_id in file_ids:\n",
|
| 51 |
" fs.delete(file_id)\n",
|
| 52 |
"\n",
|
| 53 |
+
" print(f\"✅ Đã xóa {len(file_ids)} file trong collection '{collection_name}' của db '{db_name}'\")\n",
|
| 54 |
"\n",
|
| 55 |
" except Exception as e:\n",
|
| 56 |
" print(f\"❌ Lỗi khi xóa file: {str(e)}\")\n",
|
|
|
|
| 78 |
},
|
| 79 |
{
|
| 80 |
"cell_type": "code",
|
| 81 |
+
"execution_count": 2,
|
| 82 |
"metadata": {},
|
| 83 |
"outputs": [],
|
| 84 |
"source": [
|
|
|
|
| 119 |
},
|
| 120 |
{
|
| 121 |
"cell_type": "code",
|
| 122 |
+
"execution_count": 20,
|
| 123 |
"metadata": {},
|
| 124 |
"outputs": [],
|
| 125 |
"source": [
|
|
|
|
| 150 |
},
|
| 151 |
{
|
| 152 |
"cell_type": "code",
|
| 153 |
+
"execution_count": 21,
|
| 154 |
"metadata": {},
|
| 155 |
"outputs": [],
|
| 156 |
"source": [
|
|
|
|
| 181 |
},
|
| 182 |
{
|
| 183 |
"cell_type": "code",
|
| 184 |
+
"execution_count": 24,
|
| 185 |
"metadata": {},
|
| 186 |
"outputs": [
|
| 187 |
{
|
| 188 |
"name": "stdout",
|
| 189 |
"output_type": "stream",
|
| 190 |
"text": [
|
| 191 |
+
"✅ File đã được tải về: D:\\Show_me_everything\\Machine Translation\\input\\MXL1166配套表.docx\n"
|
| 192 |
]
|
| 193 |
}
|
| 194 |
],
|
| 195 |
"source": [
|
| 196 |
+
"download_input_from_mongodb(file_id=\"684002b9047f70beae0bdf2e\", save_name=\"MXL1166配套表.docx\", db_name=\"word\", collection_name=\"root_file\")"
|
| 197 |
]
|
| 198 |
},
|
| 199 |
{
|
| 200 |
"cell_type": "code",
|
| 201 |
+
"execution_count": 25,
|
| 202 |
"metadata": {},
|
| 203 |
"outputs": [
|
| 204 |
{
|
| 205 |
"name": "stdout",
|
| 206 |
"output_type": "stream",
|
| 207 |
"text": [
|
| 208 |
+
"✅ File đã được tải về: D:\\Show_me_everything\\Machine Translation\\output\\MXL1147配套表.docx\n"
|
| 209 |
]
|
| 210 |
}
|
| 211 |
],
|
| 212 |
"source": [
|
| 213 |
+
"download_output_from_mongodb(file_id=\"68400205047f70beae0bdf2a\", save_name=\"MXL1147配套表.docx\", db_name=\"word\", collection_name=\"final_file\")"
|
| 214 |
]
|
| 215 |
},
|
| 216 |
{
|
|
|
|
| 222 |
},
|
| 223 |
{
|
| 224 |
"cell_type": "code",
|
| 225 |
+
"execution_count": 12,
|
| 226 |
"metadata": {},
|
| 227 |
"outputs": [
|
| 228 |
{
|
| 229 |
"name": "stdout",
|
| 230 |
"output_type": "stream",
|
| 231 |
"text": [
|
| 232 |
+
"✅ Đã xóa 1 file trong collection 'root_file'\n",
|
| 233 |
"✅ Đã xóa 0 file trong collection 'final_pptx'\n",
|
| 234 |
"✅ Đã xóa 0 file trong collection 'original_xml'\n",
|
| 235 |
"✅ Đã xóa 0 file trong collection 'final_xml'\n"
|
|
|
|
| 244 |
},
|
| 245 |
{
|
| 246 |
"cell_type": "code",
|
| 247 |
+
"execution_count": 6,
|
| 248 |
"metadata": {},
|
| 249 |
"outputs": [
|
| 250 |
{
|
| 251 |
"name": "stdout",
|
| 252 |
"output_type": "stream",
|
| 253 |
"text": [
|
| 254 |
+
"✅ Đã xóa 0 file trong collection 'root_file' của db 'word'\n",
|
| 255 |
+
"✅ Đã xóa 4 file trong collection 'root_file' của db 'excel'\n",
|
| 256 |
+
"✅ Đã xóa 0 file trong collection 'root_file' của db 'pptx'\n",
|
| 257 |
+
"✅ Đã xóa 0 file trong collection 'root_file' của db 'csv'\n",
|
| 258 |
+
"✅ Đã xóa 0 file trong collection 'final_file' của db 'word'\n",
|
| 259 |
+
"✅ Đã xóa 4 file trong collection 'final_file' của db 'excel'\n",
|
| 260 |
+
"✅ Đã xóa 0 file trong collection 'final_file' của db 'pptx'\n",
|
| 261 |
+
"✅ Đã xóa 0 file trong collection 'final_file' của db 'csv'\n"
|
| 262 |
]
|
| 263 |
}
|
| 264 |
],
|
| 265 |
"source": [
|
| 266 |
"for i in ['root_file', 'final_file']:\n",
|
| 267 |
+
" for j in ['word', 'excel', 'pptx', 'csv']:\n",
|
| 268 |
+
" delete_all_files_in_collection(i, db_name=j)"
|
| 269 |
+
]
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"cell_type": "code",
|
| 273 |
+
"execution_count": 7,
|
| 274 |
+
"metadata": {},
|
| 275 |
+
"outputs": [
|
| 276 |
+
{
|
| 277 |
+
"data": {
|
| 278 |
+
"text/plain": [
|
| 279 |
+
"91.66238403320312"
|
| 280 |
+
]
|
| 281 |
+
},
|
| 282 |
+
"execution_count": 7,
|
| 283 |
+
"metadata": {},
|
| 284 |
+
"output_type": "execute_result"
|
| 285 |
+
}
|
| 286 |
+
],
|
| 287 |
+
"source": [
|
| 288 |
+
"client = MongoClient(\"mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0\")\n",
|
| 289 |
+
"total_size = 0\n",
|
| 290 |
+
"\n",
|
| 291 |
+
"for db_name in ['word', 'exce', 'pptx', 'csv']:\n",
|
| 292 |
+
" db = client[db_name]\n",
|
| 293 |
+
" stats = db.command(\"dbstats\")\n",
|
| 294 |
+
" db_size = stats.get(\"dataSize\", 0)\n",
|
| 295 |
+
" total_size += db_size\n",
|
| 296 |
+
"total_size / (1024** 2)"
|
| 297 |
+
]
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"cell_type": "code",
|
| 301 |
+
"execution_count": 9,
|
| 302 |
+
"metadata": {},
|
| 303 |
+
"outputs": [
|
| 304 |
+
{
|
| 305 |
+
"data": {
|
| 306 |
+
"text/plain": [
|
| 307 |
+
"'2025-06-05 15:19:25'"
|
| 308 |
+
]
|
| 309 |
+
},
|
| 310 |
+
"execution_count": 9,
|
| 311 |
+
"metadata": {},
|
| 312 |
+
"output_type": "execute_result"
|
| 313 |
+
}
|
| 314 |
+
],
|
| 315 |
+
"source": [
|
| 316 |
+
"import time \n",
|
| 317 |
+
"now = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())\n",
|
| 318 |
+
"now"
|
| 319 |
+
]
|
| 320 |
+
},
|
| 321 |
+
{
|
| 322 |
+
"cell_type": "code",
|
| 323 |
+
"execution_count": 27,
|
| 324 |
+
"metadata": {},
|
| 325 |
+
"outputs": [
|
| 326 |
+
{
|
| 327 |
+
"ename": "OperationFailure",
|
| 328 |
+
"evalue": "(Unauthorized) not authorized on admin to execute command { fsync: 1, lsid: { id: {4 [50 114 225 195 219 36 79 24 143 231 27 7 151 76 44 22]} }, $clusterTime: { clusterTime: {1749030237 5}, signature: { hash: {0 [221 223 81 8 201 103 38 61 210 190 116 79 255 71 28 215 34 19 176 79]}, keyId: 7456826922580836352.000000 } }, $db: \"admin\" }, full error: {'ok': 0, 'errmsg': '(Unauthorized) not authorized on admin to execute command { fsync: 1, lsid: { id: {4 [50 114 225 195 219 36 79 24 143 231 27 7 151 76 44 22]} }, $clusterTime: { clusterTime: {1749030237 5}, signature: { hash: {0 [221 223 81 8 201 103 38 61 210 190 116 79 255 71 28 215 34 19 176 79]}, keyId: 7456826922580836352.000000 } }, $db: \"admin\" }', 'code': 8000, 'codeName': 'AtlasError'}",
|
| 329 |
+
"output_type": "error",
|
| 330 |
+
"traceback": [
|
| 331 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 332 |
+
"\u001b[1;31mOperationFailure\u001b[0m Traceback (most recent call last)",
|
| 333 |
+
"Cell \u001b[1;32mIn[27], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mtime\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madmin\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcommand\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfsync\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Force flush\u001b[39;00m\n\u001b[0;32m 4\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m1\u001b[39m)\n",
|
| 334 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\_csot.py:119\u001b[0m, in \u001b[0;36mapply.<locals>.csot_wrapper\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 117\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m _TimeoutContext(timeout):\n\u001b[0;32m 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m--> 119\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 335 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\synchronous\\database.py:930\u001b[0m, in \u001b[0;36mDatabase.command\u001b[1;34m(self, command, value, check, allowable_errors, read_preference, codec_options, session, comment, **kwargs)\u001b[0m\n\u001b[0;32m 925\u001b[0m read_preference \u001b[38;5;241m=\u001b[39m (session \u001b[38;5;129;01mand\u001b[39;00m session\u001b[38;5;241m.\u001b[39m_txn_read_preference()) \u001b[38;5;129;01mor\u001b[39;00m ReadPreference\u001b[38;5;241m.\u001b[39mPRIMARY\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_client\u001b[38;5;241m.\u001b[39m_conn_for_reads(read_preference, session, operation\u001b[38;5;241m=\u001b[39mcommand_name) \u001b[38;5;28;01mas\u001b[39;00m (\n\u001b[0;32m 927\u001b[0m connection,\n\u001b[0;32m 928\u001b[0m read_preference,\n\u001b[0;32m 929\u001b[0m ):\n\u001b[1;32m--> 930\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_command(\n\u001b[0;32m 931\u001b[0m connection,\n\u001b[0;32m 932\u001b[0m command,\n\u001b[0;32m 933\u001b[0m value,\n\u001b[0;32m 934\u001b[0m check,\n\u001b[0;32m 935\u001b[0m allowable_errors,\n\u001b[0;32m 936\u001b[0m read_preference,\n\u001b[0;32m 937\u001b[0m opts, \u001b[38;5;66;03m# type: ignore[arg-type]\u001b[39;00m\n\u001b[0;32m 938\u001b[0m session\u001b[38;5;241m=\u001b[39msession,\n\u001b[0;32m 939\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[0;32m 940\u001b[0m )\n",
|
| 336 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\synchronous\\database.py:770\u001b[0m, in \u001b[0;36mDatabase._command\u001b[1;34m(self, conn, command, value, check, allowable_errors, read_preference, codec_options, write_concern, parse_write_concern_error, session, **kwargs)\u001b[0m\n\u001b[0;32m 768\u001b[0m command\u001b[38;5;241m.\u001b[39mupdate(kwargs)\n\u001b[0;32m 769\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_client\u001b[38;5;241m.\u001b[39m_tmp_session(session) \u001b[38;5;28;01mas\u001b[39;00m s:\n\u001b[1;32m--> 770\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mconn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcommand\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 771\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 772\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommand\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 773\u001b[0m \u001b[43m \u001b[49m\u001b[43mread_preference\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 774\u001b[0m \u001b[43m \u001b[49m\u001b[43mcodec_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 775\u001b[0m \u001b[43m \u001b[49m\u001b[43mcheck\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 776\u001b[0m \u001b[43m \u001b[49m\u001b[43mallowable_errors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 777\u001b[0m \u001b[43m \u001b[49m\u001b[43mwrite_concern\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwrite_concern\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 778\u001b[0m \u001b[43m \u001b[49m\u001b[43mparse_write_concern_error\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparse_write_concern_error\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 779\u001b[0m \u001b[43m \u001b[49m\u001b[43msession\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43ms\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 780\u001b[0m \u001b[43m \u001b[49m\u001b[43mclient\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_client\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 781\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
|
| 337 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\synchronous\\helpers.py:47\u001b[0m, in \u001b[0;36m_handle_reauth.<locals>.inner\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mpymongo\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msynchronous\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpool\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Connection\n\u001b[0;32m 46\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m---> 47\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 48\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m OperationFailure \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[0;32m 49\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m no_reauth:\n",
|
| 338 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\synchronous\\pool.py:536\u001b[0m, in \u001b[0;36mConnection.command\u001b[1;34m(self, dbname, spec, read_preference, codec_options, check, allowable_errors, read_concern, write_concern, parse_write_concern_error, collation, session, client, retryable_write, publish_events, user_fields, exhaust_allowed)\u001b[0m\n\u001b[0;32m 534\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_raise_if_not_writable(unacknowledged)\n\u001b[0;32m 535\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 536\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcommand\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 537\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 538\u001b[0m \u001b[43m \u001b[49m\u001b[43mdbname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 539\u001b[0m \u001b[43m \u001b[49m\u001b[43mspec\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 540\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mis_mongos\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 541\u001b[0m \u001b[43m \u001b[49m\u001b[43mread_preference\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 542\u001b[0m \u001b[43m \u001b[49m\u001b[43mcodec_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 543\u001b[0m \u001b[43m \u001b[49m\u001b[43msession\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 544\u001b[0m \u001b[43m \u001b[49m\u001b[43mclient\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 545\u001b[0m \u001b[43m \u001b[49m\u001b[43mcheck\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 546\u001b[0m \u001b[43m \u001b[49m\u001b[43mallowable_errors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 547\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maddress\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 548\u001b[0m \u001b[43m \u001b[49m\u001b[43mlisteners\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 549\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmax_bson_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 550\u001b[0m \u001b[43m \u001b[49m\u001b[43mread_concern\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 551\u001b[0m \u001b[43m \u001b[49m\u001b[43mparse_write_concern_error\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparse_write_concern_error\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 552\u001b[0m \u001b[43m \u001b[49m\u001b[43mcollation\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcollation\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 553\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression_ctx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompression_context\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 554\u001b[0m \u001b[43m \u001b[49m\u001b[43muse_op_msg\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mop_msg_enabled\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 555\u001b[0m \u001b[43m \u001b[49m\u001b[43munacknowledged\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43munacknowledged\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 556\u001b[0m \u001b[43m \u001b[49m\u001b[43muser_fields\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muser_fields\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 557\u001b[0m \u001b[43m \u001b[49m\u001b[43mexhaust_allowed\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexhaust_allowed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 558\u001b[0m \u001b[43m \u001b[49m\u001b[43mwrite_concern\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwrite_concern\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 559\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 560\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (OperationFailure, NotPrimaryError):\n\u001b[0;32m 561\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m\n",
|
| 339 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\synchronous\\network.py:213\u001b[0m, in \u001b[0;36mcommand\u001b[1;34m(conn, dbname, spec, is_mongos, read_preference, codec_options, session, client, check, allowable_errors, address, listeners, max_bson_size, read_concern, parse_write_concern_error, collation, compression_ctx, use_op_msg, unacknowledged, user_fields, exhaust_allowed, write_concern)\u001b[0m\n\u001b[0;32m 211\u001b[0m client\u001b[38;5;241m.\u001b[39m_process_response(response_doc, session)\n\u001b[0;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check:\n\u001b[1;32m--> 213\u001b[0m \u001b[43mhelpers_shared\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_check_command_response\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 214\u001b[0m \u001b[43m \u001b[49m\u001b[43mresponse_doc\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 215\u001b[0m \u001b[43m \u001b[49m\u001b[43mconn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmax_wire_version\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 216\u001b[0m \u001b[43m \u001b[49m\u001b[43mallowable_errors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 217\u001b[0m \u001b[43m \u001b[49m\u001b[43mparse_write_concern_error\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparse_write_concern_error\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 218\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 219\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[0;32m 220\u001b[0m duration \u001b[38;5;241m=\u001b[39m datetime\u001b[38;5;241m.\u001b[39mdatetime\u001b[38;5;241m.\u001b[39mnow() \u001b[38;5;241m-\u001b[39m start\n",
|
| 340 |
+
"File \u001b[1;32md:\\Miniconda\\envs\\machine_translate\\lib\\site-packages\\pymongo\\helpers_shared.py:247\u001b[0m, in \u001b[0;36m_check_command_response\u001b[1;34m(response, max_wire_version, allowable_errors, parse_write_concern_error)\u001b[0m\n\u001b[0;32m 244\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m43\u001b[39m:\n\u001b[0;32m 245\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CursorNotFound(errmsg, code, response, max_wire_version)\n\u001b[1;32m--> 247\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m OperationFailure(errmsg, code, response, max_wire_version)\n",
|
| 341 |
+
"\u001b[1;31mOperationFailure\u001b[0m: (Unauthorized) not authorized on admin to execute command { fsync: 1, lsid: { id: {4 [50 114 225 195 219 36 79 24 143 231 27 7 151 76 44 22]} }, $clusterTime: { clusterTime: {1749030237 5}, signature: { hash: {0 [221 223 81 8 201 103 38 61 210 190 116 79 255 71 28 215 34 19 176 79]}, keyId: 7456826922580836352.000000 } }, $db: \"admin\" }, full error: {'ok': 0, 'errmsg': '(Unauthorized) not authorized on admin to execute command { fsync: 1, lsid: { id: {4 [50 114 225 195 219 36 79 24 143 231 27 7 151 76 44 22]} }, $clusterTime: { clusterTime: {1749030237 5}, signature: { hash: {0 [221 223 81 8 201 103 38 61 210 190 116 79 255 71 28 215 34 19 176 79]}, keyId: 7456826922580836352.000000 } }, $db: \"admin\" }', 'code': 8000, 'codeName': 'AtlasError'}"
|
| 342 |
+
]
|
| 343 |
+
}
|
| 344 |
+
],
|
| 345 |
+
"source": [
|
| 346 |
+
"import time\n",
|
| 347 |
+
"\n",
|
| 348 |
+
"client.admin.command(\"fsync\") # Force flush\n",
|
| 349 |
+
"time.sleep(1)"
|
| 350 |
]
|
| 351 |
},
|
| 352 |
{
|