Files
hpos-data/changeTestStatus.py

33 lines
1.3 KiB
Python
Raw Normal View History

2023-08-11 13:32:13 +00:00
import firebase_admin
from firebase_admin import credentials, firestore
2023-08-21 14:39:15 +05:30
import os
2023-09-11 17:32:11 +05:30
from google.cloud.firestore_v1.base_query import FieldFilter
2023-08-11 13:32:13 +00:00
2023-09-11 17:32:11 +05:30
key_path = os.getcwd() + '/scripts/keys/hpos-preprod-firebase-adminsdk-d6jjt-ae42ad0f67.json'
2023-08-11 13:32:13 +00:00
# Replace 'path/to/your/serviceAccountKey.json' with the actual path to your service account JSON file
2023-08-21 14:39:15 +05:30
cred = credentials.Certificate(key_path)
2023-08-11 13:32:13 +00:00
firebase_admin.initialize_app(cred)
def move_documents(source_collection):
db = firestore.client()
# Get all documents from the source collection
2023-09-11 17:32:11 +05:30
source_docs = db.collection(source_collection).where(filter=FieldFilter("name", "==", " S2-A-R1")).stream()
2023-08-11 13:32:13 +00:00
for doc in source_docs:
# Extract the document ID
doc_id = doc.id
2023-09-11 17:32:11 +05:30
print(doc_id)
2023-08-11 13:32:13 +00:00
# Get the document data
doc_data = doc.to_dict()
try:
# Delete the document from the source collection
2023-08-21 14:39:15 +05:30
db.collection(source_collection).document(doc_id).update({"testStatus": True})
2023-08-11 13:32:13 +00:00
print(f"Document with ID '{doc_id}' updated")
except Exception as e:
print(f"Error deleting document with ID '{doc_id}' from the source collection: {e}")
if __name__ == "__main__":
# Replace 'source_collection' and 'destination_collection' with your collection names
move_documents("patientData")