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

findAndModify breaks when I use the query operator "$in" and the update operator "$addToSet" on the same field.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 3.4.1
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Sprint:
      Query 2017-02-13, Query 2017-03-27

      Description

      The following command works in version 3.2.6, but not in 3.4.1:

      db.testing.findAndModify({ query: { tags: { $in: ['y'] } }, update: { $addToSet: { tags: 'y' } }, upsert: true, new: true })
      

      This is the error I get in 3.4.1:

      QUERY    [main] Error: findAndModifyFailed failed: {
        "ok" : 0,
        "errmsg" : "Cannot apply $addToSet to a non-array field. Field named 'tags' has a non-array type string in the document INVALID-MUTABLE-ELEMENT",
        "code" : 16836,
        "codeName" : "Location16836"
      }
      

      If I change the query field from 'tags' to another name such as 'labels', it works. Also, I made sure to test this on completely new collections, so the result has nothing to do with existing documents in the database.

      While this behavior seems similar to the bug documented here - https://jira.mongodb.org/browse/SERVER-3946 - I am reporting it since this behavior worked in a more recent version of MongoDB. Thanks.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              david.storch David Storch
              Reporter:
              mattruzicka@gmail.com Matthew Ruzicka
              Participants:
              Votes:
              2 Vote for this issue
              Watchers:
              14 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: