# 2-> 1 subs 1 baseline import json file_path = "referOneSub" with open(file_path, 'r') as file: data = json.load(file) data_array = data['data'] insert_object_ids = [ObjectId(_id) for _id in data_array] print(len(insert_object_ids)) # print(insert_object_ids) from bson.objectid import ObjectId for _id in insert_object_ids: # print("one") record = db["participantBaselineAndFollowupData"].find_one({"_id": _id}) if record: user_id = record["participantId"] subscription = db["subscription"].find_one({"userId": user_id}) if subscription: program_start_date = subscription.get("startDate", "") program_code = subscription["subscriptionPlan"].get("programCode", "") db["participantBaselineAndFollowupData"].update_one( {"_id": _id}, {"$set": {"programCode": program_code, "programStartDate": program_start_date}} ) print("completed")
Preview:
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