optimize update with batch mode
This commit is contained in:
@@ -9,24 +9,20 @@ import sys
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
# Initialize Firebase Admin SDK
|
cred = credentials.Certificate(os.getcwd() + '/keys/hpos-prod-firebase-adminsdk.json')
|
||||||
cred = credentials.Certificate(os.getcwd() + '/keys/hpos-prod-firebase-adminsdk.json') # Replace with your own service account key path
|
|
||||||
firebase_admin.initialize_app(cred)
|
firebase_admin.initialize_app(cred)
|
||||||
|
|
||||||
# Get a reference to the Firestore database
|
|
||||||
db = firestore.client()
|
db = firestore.client()
|
||||||
|
|
||||||
# Specify the collections
|
|
||||||
patient_collection = db.collection("patientData")
|
patient_collection = db.collection("patientData")
|
||||||
test_collection = db.collection("testData")
|
test_collection = db.collection("testData")
|
||||||
# start_date = sys.argv[1] # '2023-01-12' #input("Please enter the start date (yyyy-mm-dd): ")
|
|
||||||
# end_date = sys.argv[2] #'2023-07-16' #input("Please enter the end date (yyyy-mm-dd): ")
|
|
||||||
|
|
||||||
query = patient_collection.where(filter=FieldFilter("createdAt", ">=", "2023-11-07")).where(filter=FieldFilter("createdAt", "<", "2023-11-08"))
|
query = patient_collection.where(filter=FieldFilter("createdAt", ">=", "2023-11-07")).where(filter=FieldFilter("createdAt", "<", "2023-11-08"))
|
||||||
#.where(filter=FieldFilter("registrationCenterName", "==", "SCS high school"))
|
#.where(filter=FieldFilter("registrationCenterName", "==", "SCS high school"))
|
||||||
patient_docs = query.stream()
|
patient_docs = query.stream()
|
||||||
|
|
||||||
# Prepare data to store in CSV
|
batch = db.batch()
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for patient_doc in patient_docs:
|
for patient_doc in patient_docs:
|
||||||
patient_data = patient_doc.to_dict()
|
patient_data = patient_doc.to_dict()
|
||||||
@@ -39,5 +35,8 @@ for patient_doc in patient_docs:
|
|||||||
if "LAL" in patient_data['_id']:
|
if "LAL" in patient_data['_id']:
|
||||||
# print("ADA")
|
# print("ADA")
|
||||||
print(patient_data['_id'])
|
print(patient_data['_id'])
|
||||||
db.collection("patientData").document(patient_doc.id).update({"_idSearch": '20231108' + patient_data['_id']})
|
doc_ref = db.collection("patientData").document(patient_doc.id)
|
||||||
|
batch.update(doc_ref, {"_idSearch": '20231108' + patient_data['_id']})
|
||||||
|
|
||||||
|
batch.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user