Apologies; I did read the documentation but am not quite understanding it well enough to assume how to use the ‘has’ component.
A sample document is below:
"Variant": [
{
"Gene": "ACADVL",
"Genomic Coordinate GRCh37": "17:g.7124860?",
"Genomic Coordinate GRCh38": "17:g.7221541?",
"Transcript": "NM_000018.4",
"Variant (cDNA)": "c.?",
"Start Position": "481",
"Variant Location": "Exon 7",
"HGVS": "NM_000018.4:c.?",
"Effect Type": "Missense",
"Amino Acid Change": "p.Ala161Thr",
"Predicted ACMG Call": "likely_pathogenic",
"GNOMAD Frequency": "NA"
},
{
"Gene": "ACADVL",
"Genomic Coordinate GRCh37": "17:g.7125591?",
"Genomic Coordinate GRCh38": "17:g.7222272?",
"Transcript": "NM_000018.4",
"Variant (cDNA)": "c.?",
"Start Position": "848",
"Variant Location": "Exon 9",
"HGVS": "NM_000018.4:c.?",
"Amino Acid Change": "p.Val283Ala",
"Predicted ACMG Call": "likely_pathogenic"
}
]
Your suggestion worked, but unfortunately for me it adds the Predicted cDNA field to each array item (This is because there are two variants with c.? but different amino acid outcomes. I tried editing your script to include the additional filter so that it is only added to array items that include both cDNA "c.?’ and amino acid change of “p.Ala161Thr”. However, it seems I cannot use hasVariant twice, and am getting a clone error when playing with the code. I still do not quite understand the different between hasVariant vs Variant.Variant (cDNA).
db.LCFAOD.updateMany( {
"Variant.Amino Acid Change": "p.Ala161Thr"
},
{
"$set": {
"Variant.$[hasVariant].Predicted cDNA": "c.481G>A"
}
},
{ arrayFilters : [
{
"hasVariant.Variant (cDNA)": "c.?",
"hasVariant.Amino Acid Change": "p.Ala161Thr"
}
}
]
})
Error: clone(t={}){const r=t.loc||{};return e({loc:new Position("line"in r?r.line:this.loc.line,"column"in r?r.column:……)} could not be cloned.
db.LCFAOD.updateMany( {
"Variant.Amino Acid Change": "p.Ala161Thr"
},
{
"$set": {
"Variant.$[hasVariant].Predicted cDNA": "c.481G>A"
}
},
{ arrayFilters : [
{
"hasVariant.Variant (cDNA)": "c.?"
},
{
"hasVariant.Amino Acid Change": "p.Ala161Thr"
}
]
}
)
MongoServerError: Found multiple array filters with the same top-level field name hasVariant
Again, appreciate the help. I am quite new to Mongo