Preview:
#3-> one baseline 2 subs refer the given program code
import json

file_path = "oneBase2Sub"
try:
    with open(file_path, "r") as file:
        data1 = json.load(file)
        # print(data)

    data_list = list(data1.items())
    # print(data_list)
except Exception as e:
    print("Error:", e)


print(len(data_list))

for data_tuple in data_list:
    _id, program_code = data_tuple

    participant_record = db["participantBaselineAndFollowupData"].find_one({"_id": ObjectId(_id)})

    if participant_record:
        user_id = participant_record["participantId"]

        subscription_record = db["subscription"].find_one({"userId": user_id, "subscriptionPlan.programCode": program_code})
        
        if subscription_record:
            program_start_date = subscription_record.get("startDate", "")
            program_code_from_subscription = subscription_record["subscriptionPlan"].get("programCode", "")
#             print(program_start_date)
#             print(program_code_from_subscription)
            db["participantBaselineAndFollowupData"].update_one(
                {"_id": participant_record["_id"]},
                {"$set": {"programCode": program_code, "programStartDate": program_start_date}}
            )
print("Completed")
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter