add clearUsers functions
This commit is contained in:
32
cloud-functions/python/functions/clearusers.py
Normal file
32
cloud-functions/python/functions/clearusers.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import firebase_admin
|
||||||
|
from firebase_admin import credentials, firestore
|
||||||
|
import os
|
||||||
|
from google.cloud.firestore_v1.base_query import FieldFilter
|
||||||
|
|
||||||
|
key_path = os.getcwd() + '/scripts/keys/hpos-preprod-firebase-adminsdk-d6jjt-ae42ad0f67.json'
|
||||||
|
# Replace 'path/to/your/serviceAccountKey.json' with the actual path to your service account JSON file
|
||||||
|
cred = credentials.Certificate(key_path)
|
||||||
|
firebase_admin.initialize_app(cred)
|
||||||
|
def move_documents(source_collection):
|
||||||
|
db = firestore.client()
|
||||||
|
|
||||||
|
# Get all documents from the source collection
|
||||||
|
source_docs = db.collection(source_collection).where(filter=FieldFilter("testStatus", "==", False)).stream()
|
||||||
|
for doc in source_docs:
|
||||||
|
# Extract the document ID
|
||||||
|
doc_id = doc.id
|
||||||
|
print(doc_id)
|
||||||
|
|
||||||
|
# Get the document data
|
||||||
|
doc_data = doc.to_dict()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Delete the document from the source collection
|
||||||
|
db.collection(source_collection).document(doc_id).update({"testStatus": True})
|
||||||
|
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")
|
||||||
@@ -2,3 +2,4 @@ functions-framework==3.*
|
|||||||
firebase_functions~=0.1.0
|
firebase_functions~=0.1.0
|
||||||
pandas==2.0.3
|
pandas==2.0.3
|
||||||
openpyxl==3.1.2
|
openpyxl==3.1.2
|
||||||
|
firebase-admin==6.2.0
|
||||||
Reference in New Issue
Block a user