(20241008) logging decorator and model improved.
This commit is contained in:
@@ -1691,42 +1691,43 @@ if __name__ == "__main__":
|
||||
async def main():
|
||||
|
||||
# Create an instance of the database connector:
|
||||
my_fs = AsyncMongoStorage(
|
||||
connection_string = constants.MONGO_FILE_CONNECTION_STRING,
|
||||
database_name = constants.MONGO_FILE_DATABASE_NAME,
|
||||
my_db = AsyncMongo(
|
||||
connection_string = constants.MONGO_DATA_CONNECTION_STRING,
|
||||
database_name = constants.MONGO_DATA_DATABASE_NAME,
|
||||
max_connections = 10,
|
||||
debug = True
|
||||
)
|
||||
|
||||
# Connect to the database:
|
||||
await my_fs.connect()
|
||||
await my_db.connect()
|
||||
|
||||
# Keep performing the changes in batches till you have corrections to make:
|
||||
while True:
|
||||
# # Get the documents to migrate:
|
||||
# documents = await my_db.find_many(
|
||||
# collection = "scriptData",
|
||||
# filter = {},
|
||||
# limit = 50,
|
||||
# projection = {"_id": False}
|
||||
# )
|
||||
# # print(json.to_string(documents, default = str))
|
||||
#
|
||||
# # Adjust them:
|
||||
# adjusted_documents = []
|
||||
# for document in documents:
|
||||
# script_id = document.pop("scriptId")
|
||||
# adjusted_document = {
|
||||
# "scriptId": script_id,
|
||||
# "desc": "no desc",
|
||||
# "content": document
|
||||
# }
|
||||
# adjusted_documents.append(adjusted_document)
|
||||
# print(json.to_string(adjusted_documents, default = str))
|
||||
#
|
||||
# # Insert the adjusted ones to the new collection:
|
||||
# response = await my_db.insert_many(
|
||||
# collection = "_scriptData",
|
||||
# documents = adjusted_documents
|
||||
# )
|
||||
# print("RESPONSE:", response)
|
||||
|
||||
# Find all the files that have their metadata as a string:
|
||||
files = await my_fs.find_many(
|
||||
filter = {
|
||||
"metadata": {"$type": "string"}
|
||||
},
|
||||
limit = 10
|
||||
)
|
||||
|
||||
print(my_fs.to_json_string(files))
|
||||
break
|
||||
|
||||
# # If no matches were found:
|
||||
# if not files: break
|
||||
#
|
||||
# # Fix the metadata file-by-file:
|
||||
# for file in files:
|
||||
# file_id = file["_id"]
|
||||
# success = await my_fs.replace_metadata_for_one(
|
||||
# filter = {"_id": file_id},
|
||||
# replacement = json.from_string(file["metadata"])
|
||||
# )
|
||||
# print(file_id, ":", success)
|
||||
|
||||
print("Fixes done!")
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
Reference in New Issue
Block a user