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

upsert querying an array field and $push-ing to that same field yields confusing error

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0
    • Component/s: Write Ops
    • None
    • ALL
    • Quint 9 09/18/15

      When attempting to query on one field of an array element, the docs make it very clear that $elemMatch is not necessary.

      For example, find({"list.field":"value"}) should match the following document: { "list":[ {"field":"value"}, {"otherField":"otherValue"} ] }.

      However, doing an upsert using findAndModify on an empty collection:

       findAndModify(
        {"list.field":"value"},
        {"$push":{"list":{"field":"value"}}},
        {"upsert":1}
      )
      

      causes the following error:
      "list" must be an array but is of type Object in document {INVALID-MUTABLE-ELEMENT}

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            evan.altman@ticketmaster.com Evan Altman
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: