-
Type: Bug
-
Resolution: Works as Designed
-
Priority: 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.
- related to
-
SERVER-21065 Optimizer should consider predicate with "$in" operator having a single argument to be equivalent to the equality operator
- Closed
-
SERVER-3946 Update with $addToSet/$push with a query on same field is broken during insert
- Closed