How to insert JSON or XML SOAP response into a MongoDB collection

I would like to store the results of a SOAP call into a collection. The response is pretty massive and I only actually need a few piece of data from it.

Below is a very small piece of a single results record that I logged using JSON.stringify(result, null, 2) to illustrate the structure

I tried a bunch of random things to get those results (even a full dump) into a collection but any way i tried threw errors

I couldn’t find a sample after a day of googling that would work for me so I thought I’d check here if someone could show me a way to grab certain pieces of this record even when they are several levels deep and insert them into a collection.

Thanks!

{
“attributes”: {
“sl:version”: “v25.0”
},
“Request_Criteria”: {
“Sent_After”: “2015-07-12T07:00:00.000Z”
},
“Response_Results”: {
“Total_Results”: “348”,
“Total_Pages”: “4”,
“Page_Results”: “100”,
“Page”: “1”
},
“Response_Data”: {
“My_Event”: [
{
“My_Event_Reference”: {
“attributes”: {
“sl:Descriptor”: “Some description”
},
“ID”: [
{
“attributes”: {
“sl:type”: “DID”
},
"$value": “500599d330f01062e”
},
{
“attributes”: {
“sl:type”: “Instance_ID”
},
"$value": “My_INVOKER_81”
}
]
},
“My_Event_Data”: {
“My_System_Reference”: {
“attributes”: {
“sl:Descriptor”: “Another desc”
},
“ID”: [
{
“attributes”: {
“sl:type”: “DID”
},
"$value": “96fee7a1679f105e514a0”
},
{
“attributes”: {
“sl:type”: “My_System_ID”
},
"$value": “TESTER”
}
]
},

I made some progress by looping through the resultset.

Still having a hard time finding a syntax for picking a value I want when I have something like this sitting at the bottom of my structure.

“ID”: [
{ attributes: { ‘js:type’: ‘DID’ },’$value’: ‘04febdf3e00d’ },
{ attributes: { ‘js:type’: ‘Name’ }, ‘$value’: ‘Some Name’ }
]

I can drill down to the $value where type = DID for example by explicitly stating its position in the array
like this grandparent.parent.ID[0].$value but I’d rather not depend on the position never changing.

I’m looking for the correct syntax to get to the $value when type = DID.