Spaces:
Running
Running
add time
Browse files- db/__pycache__/mongodb.cpython-310.pyc +0 -0
- db/mongodb.py +2 -8
db/__pycache__/mongodb.cpython-310.pyc
CHANGED
|
Binary files a/db/__pycache__/mongodb.cpython-310.pyc and b/db/__pycache__/mongodb.cpython-310.pyc differ
|
|
|
db/mongodb.py
CHANGED
|
@@ -12,12 +12,6 @@ def connect_mongodb(db_name, collection_name):
|
|
| 12 |
fs = gridfs.GridFS(db, collection=collection_name)
|
| 13 |
return fs
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
import gridfs
|
| 18 |
-
from pymongo import MongoClient
|
| 19 |
-
import pprint
|
| 20 |
-
|
| 21 |
def save_file_to_mongodb(uploaded_file, db_name="pptx", collection_name="root_file", max_db_size_mb=500):
|
| 22 |
client = MongoClient("mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0")
|
| 23 |
db = client[db_name]
|
|
@@ -38,11 +32,11 @@ def save_file_to_mongodb(uploaded_file, db_name="pptx", collection_name="root_fi
|
|
| 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:
|
| 42 |
return file_id, file_name
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
-
print(f"❌ Lỗi khi lưu file hoặc truy vấn MongoDB: {e}")
|
| 46 |
return None, None
|
| 47 |
|
| 48 |
finally:
|
|
|
|
| 12 |
fs = gridfs.GridFS(db, collection=collection_name)
|
| 13 |
return fs
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def save_file_to_mongodb(uploaded_file, db_name="pptx", collection_name="root_file", max_db_size_mb=500):
|
| 16 |
client = MongoClient("mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0")
|
| 17 |
db = client[db_name]
|
|
|
|
| 32 |
# Sau khi dọn dẹp (nếu cần), tiến hành lưu
|
| 33 |
file_id = fs.put(file_bytes, filename=file_name)
|
| 34 |
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
| 35 |
+
print(f"{now:} File '{file_name}' đã được lưu vào '{collection_name}' với ID: {file_id} \n")
|
| 36 |
return file_id, file_name
|
| 37 |
|
| 38 |
except Exception as e:
|
| 39 |
+
print(f"❌ Lỗi khi lưu file hoặc truy vấn MongoDB: {e} \n")
|
| 40 |
return None, None
|
| 41 |
|
| 42 |
finally:
|