Newbie help on query for embedded objects

just starting with Mongodb.

Trying to query the embedded object code_values below, for a specific one, and a generic query to pull all code_values for all documents to get a list of all that are used.
I can query the simple program_name, but have issues on the embedded objects
record_structure,code_values,recset,email_addresses,file_paths
Any help is apprecaiated:
sample record is -
[{
“_id”: {
“$oid”: “671693da49497e37ab515e5c”
},
“program_name”: “bw_xxx_xxx1205_post_acxxxx_xxx”,
“drop_program_names”: [
“xxx_xxx1205_post_acxxx_xxx”
],
“create_program_names”: [
“xxx_xxx1205_post_acxxx_xxx”
],
“record_structure”: {
“recset”: {
“rs_patname”: “vc”,
“rs_dob”: “vc”,
“rs_mrn”: “vc”,
“rs_fin”: “vc”,
“rs_encntrid”: “f8”,
“rs_payors”: “vc”,
“rs_dischdisp”: “vc”,
“rs_dischdate”: “vc”,
“rs_refsnf”: “vc”,
“rs_refhh”: “vc”,
“rs_refhosp”: “vc”,
“rs_refltacs”: “vc”,
“rs_refira”: “vc”,
“rs_refhi”: “vc”,
“rs_refdme”: “vc”,
“rs_reftrans”: “vc”,
“rs_refoutther”: “vc”,
“rs_refothserv”: “vc”,
“rs_reftodial”: “vc”,
“rs_reftoboard”: “vc”,
“rs_reftoshelt”: “vc”,
“rs_refhi_nomid”: “vc”,
“rs_refhi_evid”: “f8”,
“rs_refoutther_nomid”: “vc”,
“rs_refoutther_evid”: “f8”,
“rs_reftrans_nomid”: “vc”,
“rs_reftrans_evid”: “f8”,
“rs_reftoboard_nomid”: “vc”,
“rs_reftoboard_evid”: “f8”,
“rs_reftodial_nomid”: “vc”,
“rs_reftodial_evid”: “f8”,
“rs_refhosp_nomid”: “vc”,
“rs_refhosp_evid”: “f8”,
“rs_refltacs_nomid”: “vc”,
“rs_refltacs_evid”: “f8”,
“rs_refothserv_nomid”: “vc”,
“rs_refothserv_evid”: “f8”,
“rs_reftoshelt_nomid”: “vc”,
“rs_reftoshelt_evid”: “f8”,
“rs_refsnf_nomid”: “vc”,
“rs_refsnf_evid”: “f8”,
“rs_refhh_nomid”: “vc”,
“rs_refhh_evid”: “f8”,
“rs_refira_nomid”: “vc”,
“rs_refira_evid”: “f8”
}
},
“code_values”: {
“138906674.00”: “Referral To Skilled Nursing Facility”,
“138906232.00”: “Referral For Home Health”,
“138907671.00”: “Referral To Hospice”,
“138907289.00”: “Referral To LTACS”,
“826598935.00”: “Referral To Inpatient Rehab Acute”,
“138907508.00”: “Referral For Home Infusion”,
“138905880.00”: “Referral For DME”,
“138907783.00”: “Referral For Transportation”,
“258503279.00”: “Referral For Outpatient Therapy”,
“258503152.00”: “Referral To Other Service”,
“12502729907.00”: “Referral To Dialysis”,
“12502729999.00”: “Referral To Shelter”,
“12502729857.00”: “Referral To Boarding Home”
},
“email_addresses”: {
“Payor_1”: [
“Postxxxxx@xxxxx.eyy”,
“bww_reports@xxxxx.eyy”
],
“Payor_2_Hxxxxx”: [
bxxxxx@hxxxx.com”,
cxxxs@hxxxx.com”,
“rxxx@uxxxx.edyy”,
“cyxxxxx@uxxxx.eyy”
],
“Payor_3_Unxxxx”: [
“ljxxxxx@uxxxx.eyy”,
“jyxxxx@uxxxxx.eyy”,
“rdxxx@uxxxxx.eyy”,
“cxxxxx@ucxxxxx.eyy”,
“dxxxxxxx@uxxxxx.eyy”
]
},
“uar_functions”: [
“uar_get_code_display”
],
“file_paths”: {
“output_file”: “/xxxxxx/d_xxxx/data/xxxx_acute_xxx_YYYY-MM-DD.csv”,
“base_path”: “\\xxx-ftp.yy.xx.xxx.yyu\ftp\cccdm\RD_xxxxx\Input\”,
“backup_path”: “\\xxx-ftp.yy.xx.xxx.yyu\ftp\cccdm\RD_xxxxx\New Model\”
},
“csv_header”: [
“Name”,
“DOB”,
“MRN”,
“FIN”,
“Payors”,
“Discharge Disp”,
“Discharge Date”,
“Referral To Skilled Nursing Facility”,
“Referral For Home Health”,
“Referral To Hospice”,
“Referral To LTACS”,
“Referral To Inpatient Rehab Acute”,
“Referral For Home Infusion”,
“Referral For DME”,
“Referral For Transportation”,
“Referral For Outpatient Therapy”,
“Referral To Other Service”,
“Referral To Dialysis”,
“Referral To Boarding Home”,
“Referral To Shelter”,
“Referral To SNF NomenclatureID”,
“Referral For Home Health NomenclatureID”,
“Referral To Hospice NomenclatureID”,
“Referral To LTACS NomenclatureID”,
“Referral To Inpatient Rehab Acute NomenclatureID”,
“Referral For Home Infusion NomenclatureID”,
“Referral For Transportation NomenclatureID”,
“Referral For Outpatient Therapy NomenclatureID”,
“Referral To Other Service NomenclatureID”,
“Referral To Dialysis NomenclatureID”,
“Referral To Boarding Home NomenclatureID”,
“Referral To Shelter NomenclatureID”
]
}

You’ll want to check out how to format code and data fragments, you can use the buttons above to do this as it makes things a LOT easier for people to take what you post and try it out.

I’m not 100% sure I understand what you want but I think it could be something like this if you want to get a list of distinct values in that field.
You could use objectToArray to convert it, unwind them and then finally group them all up.

Example:

I would be a touch wary though, this will not be that performant if you have moderate quantities of data, I’ve not tested it with large volumes though so if you take this approach you’ll need to check that out.

2 Likes

Thanks so much for the help!!

Much appreciated.

Regards
Bryan