Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11531

Cannot $rename to/from an array field

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.4
    • Affects Version/s: 2.5.3
    • Component/s: Write Ops
    • ALL

      Expected: $rename field 'a' to field 'b' should replace field 'b' if it already exists, regardless of the data type stored at 'b'.

      Actual: If 'b' is an array, then the $rename returns an error instead.

      Example:

      > db.x.save({_id: 1, a: 2, b: []})
      > db.x.update({_id: 1}, {$rename: {a: "b"}})
      The destination field cannot be an array element, 'a' in doc with _id: 1.0 has an array field called 'b'
      > db.x.findOne()
      { "_id" : 1, "a" : 2, "b" : [ ] }
      

      On the other hand, if "b" stores an object instead of an array, this works as expected:

      > db.x.save({_id: 1, a: 2, b: {}})
      > db.x.update({_id: 1}, {$rename: {a: "b"}})
      > db.x.findOne()
      { "_id" : 1, "b" : 2 }
      

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: