{ "_comment": [ "Inputs only. Expectations are measured -- see record.js.", "`$addToSet`, `$pop` and `$pullAll`: the three array operators that are", "neither `$push` nor `$pull`. Each has a shape that decides whether it", "wrote at all -- a set that already held the value, a pop of an empty", "array, a pullAll matching nothing -- and `modifiedCount` is the only", "place that shows, which is why every case records an outcome too." ], "documents": [{ "_id": 1, "t": [1, 2, 3] }], "cases": [ { "description": "$addToSet appends a value the array does not hold", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": 4 } } } }, { "description": "$addToSet on a value already there writes nothing", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": 2 } } } }, { "description": "$addToSet on a missing field creates the array", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "gone": 1 } } } }, { "description": "$addToSet $each adds only what is missing", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": { "$each": [2, 4, 5] } } } } }, { "description": "$addToSet $each with duplicates inside it", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": { "$each": [7, 7] } } } } }, { "description": "$addToSet compares documents whole", "documents": [{ "_id": 1, "t": [{ "a": 1 }] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": { "a": 1 } } } } }, { "description": "$addToSet distinguishes documents by field order", "documents": [{ "_id": 1, "t": [{ "a": 1, "b": 2 }] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": { "b": 2, "a": 1 } } } } }, { "description": "$addToSet treats an int and an equal double as one value", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": 2.0 } } } }, { "description": "$addToSet on a non-array field", "documents": [{ "_id": 1, "t": 5 }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "t": 1 } } } }, { "description": "$pop removes the last element", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": 1 } } } }, { "description": "$pop with -1 removes the first", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": -1 } } } }, { "description": "$pop of an empty array writes nothing", "documents": [{ "_id": 1, "t": [] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": 1 } } } }, { "description": "$pop of a missing field writes nothing", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "gone": 1 } } } }, { "description": "$pop of a one-element array leaves an empty one", "documents": [{ "_id": 1, "t": [9] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": 1 } } } }, { "description": "$pop with an argument that is neither 1 nor -1", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": 2 } } } }, { "description": "$pop with 1.0, which is 1", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": 1.0 } } } }, { "description": "$pop of a non-array field", "documents": [{ "_id": 1, "t": 5 }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "t": 1 } } } }, { "description": "$pullAll removes every copy of every listed value", "documents": [{ "_id": 1, "t": [1, 2, 3, 2] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "t": [2] } } } }, { "description": "$pullAll with several values", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "t": [1, 3] } } } }, { "description": "$pullAll matching nothing writes nothing", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "t": [9] } } } }, { "description": "$pullAll compares documents whole, not by predicate", "documents": [{ "_id": 1, "t": [{ "a": 1 }, { "a": 2 }] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "t": [{ "a": 1 }] } } } }, { "description": "$pullAll on a missing field writes nothing", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "gone": [1] } } } }, { "description": "$pullAll with an argument that is not an array", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "t": 1 } } } }, { "description": "$pullAll emptying the array", "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pullAll": { "t": [1, 2, 3] } } } }, { "description": "$addToSet through a positional segment", "documents": [{ "_id": 1, "y": [{ "t": [1] }, { "t": [2] }] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$addToSet": { "y.$[].t": 1 } } } }, { "description": "$pop down a dotted path", "documents": [{ "_id": 1, "n": { "t": [1, 2] } }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$pop": { "n.t": -1 } } } } ] }