0

I have document with following structure

"_id": 1,
"params": {
    "defaults": {},
    "custom": {
        "one": true,
        "two": true,
        "three": false
    }
}

I want to update all params.custom fields with "on" values if they are true or "off" values if they are false. Custom may contain different fields or be empty at all, also params might not be present. How to update all documents due to this requirement?

Community
  • 1
  • 1
Most Wanted
  • 6,254
  • 5
  • 53
  • 70
  • Which means to say that unfortunately this "switch-flipping" operation would require each document to be read and the fields inspected before setting them to the reverse value. So for whatever document(s) need to be affected, it's a process of looping each document and writing back for each one as well. – Blakes Seven Mar 09 '16 at 12:14
  • @BlakesSeven, currently I am doing this operation one-by-one for each document as in your comment. I was curious if there is an easier way to achieve this – Most Wanted Mar 09 '16 at 14:09
  • If there was then the question you were linked to here would be updated with a better approach and I would supect that solution would be highly upvoted if not changed to the accepted answer. That is generally the case, and just because something was posted years ago does not mean that it is not the most current approach to handling this. – Blakes Seven Mar 09 '16 at 23:00

0 Answers0