1

There is this MongoDB Document:

{
  "name": "First Floor",
  "years": {
    "Year 1": {
      "Class A": [
        "Nayara",
        "Steve",
        "Jean"
      ],
      "Class B": [
        "Mark",
        "James",
        "Ana"
      ]
    }
  }
}

Is there a way to update the array key name, the "Year 1" to "Year somethingelse"?

If so, could it also be used with the "Class A" and "Class B" to change it to "Class somethingelse"?

1 Answer 1

2

Yes, you should $rename

db.collection.update(query, 
                     {$rename: {'years.Year 1': 'years.Year somethingelse'}})

You can do the same with "Class A" and "Class B" fields, of course.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.