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.

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.4.1
    • Component/s: Querying
    • None
    • ALL
    • Query 2017-02-13, Query 2017-03-27

      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.

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

              Created:
              Updated:
              Resolved: