Remove _id field and improve index handling in MongoDB
- Remove MongoDB _id field from documents - Improve index existence check and creation
This commit is contained in:
parent
cfb7117dd6
commit
30f71c8acf
1 changed files with 6 additions and 1 deletions
|
|
@ -383,6 +383,8 @@ class MongoDocStatusStorage(DocStatusStorage):
|
||||||
data = doc.copy()
|
data = doc.copy()
|
||||||
# Remove deprecated content field if it exists
|
# Remove deprecated content field if it exists
|
||||||
data.pop("content", None)
|
data.pop("content", None)
|
||||||
|
# Remove MongoDB _id field if it exists
|
||||||
|
data.pop("_id", None)
|
||||||
# If file_path is not in data, use document id as file path
|
# If file_path is not in data, use document id as file path
|
||||||
if "file_path" not in data:
|
if "file_path" not in data:
|
||||||
data["file_path"] = "no-file-path"
|
data["file_path"] = "no-file-path"
|
||||||
|
|
@ -410,6 +412,8 @@ class MongoDocStatusStorage(DocStatusStorage):
|
||||||
data = doc.copy()
|
data = doc.copy()
|
||||||
# Remove deprecated content field if it exists
|
# Remove deprecated content field if it exists
|
||||||
data.pop("content", None)
|
data.pop("content", None)
|
||||||
|
# Remove MongoDB _id field if it exists
|
||||||
|
data.pop("_id", None)
|
||||||
# If file_path is not in data, use document id as file path
|
# If file_path is not in data, use document id as file path
|
||||||
if "file_path" not in data:
|
if "file_path" not in data:
|
||||||
data["file_path"] = "no-file-path"
|
data["file_path"] = "no-file-path"
|
||||||
|
|
@ -456,7 +460,8 @@ class MongoDocStatusStorage(DocStatusStorage):
|
||||||
"""Create track_id index for better query performance"""
|
"""Create track_id index for better query performance"""
|
||||||
try:
|
try:
|
||||||
# Check if index already exists
|
# Check if index already exists
|
||||||
existing_indexes = await self._data.list_indexes().to_list(length=None)
|
indexes_cursor = await self._data.list_indexes()
|
||||||
|
existing_indexes = await indexes_cursor.to_list(length=None)
|
||||||
track_id_index_exists = any(
|
track_id_index_exists = any(
|
||||||
"track_id" in idx.get("key", {}) for idx in existing_indexes
|
"track_id" in idx.get("key", {}) for idx in existing_indexes
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue