I have documents with an array field that contains nested documents (objects). On the nested objects, there is a field called “default” in which only one array item can have default=true. If another nested document had default=true, I want to mark it with default=false or remove the “default” field completely AT THE SAME MOMENT I update the desired nested document with default=true.
How can I update the document so that “white” is the only nested document with “default=true” and other nested documents have either no default property or “default=false” ?
Pseudocode:
magicUpdate("docId", "white", true) // only white should have default=true
magicUpdate("docId", "blue", true) // only blue should have default=true