diff options
author | Arun Banala <arun.banala@mongodb.com> | 2020-06-29 15:21:50 +0100 |
---|---|---|
committer | Arun Banala <arun.banala@mongodb.com> | 2020-06-29 15:21:50 +0100 |
commit | fc6a12cad9b1aacb89edb1a25d81ce6005ed1077 (patch) | |
tree | a7afb5f1ea194a543909d8c7c121c192a0a389be /jstests/aggregation | |
parent | 90e259accd8444ed30f934f46ed016a710b41afc (diff) | |
download | mongo-fc6a12cad9b1aacb89edb1a25d81ce6005ed1077.tar.gz |
Revert "SERVER-48684 Pipeline stage $set fails to set a non-existent dotted field to an object"
This reverts commit f15e454fafcf369711f6da00ccdae5a2a4f8f0cd.
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/sources/addFields/dotted_paths.js | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/jstests/aggregation/sources/addFields/dotted_paths.js b/jstests/aggregation/sources/addFields/dotted_paths.js deleted file mode 100644 index e8ecdc39d46..00000000000 --- a/jstests/aggregation/sources/addFields/dotted_paths.js +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Test the behavior of $addFields in the presence of a dotted field path. - */ -(function() { -const coll = db.add_fields_dotted_paths; -coll.drop(); - -let initObj = { - _id: 1, - arrayField: [1, {subField: [2, {}]}, [1]], - objField: {p: {q: 1}, subArr: [1]}, - otherField: "value" -}; -assert.commandWorked(coll.insert(initObj)); - -function assertAddFieldsResult(projection, expectedResults) { - assert.eq(coll.aggregate([{$addFields: projection}]).toArray(), [expectedResults]); -} - -// Test that the value gets overwritten when a field exists at a given path. -initObj["objField"]["subArr"] = "newValue"; -assertAddFieldsResult({"objField.subArr": "newValue"}, initObj); -assertAddFieldsResult({"objField.subArr": {$literal: "newValue"}}, initObj); - -// Test that a new sub-object is created when a field does not exist at a given path. All the -// existing sibling fields are retained. -initObj["objField"] = { - p: {q: 1}, - subArr: [1], // Existing fields are retained. - newSubPath: {b: "newValue"} -}; -assertAddFieldsResult({"objField.newSubPath.b": {$literal: "newValue"}}, initObj); -assertAddFieldsResult({"objField.newSubPath.b": "newValue"}, initObj); - -// When the value is a nested object. -const valueWithNestedObject = { - newSubObj: [{p: "newValue"}] -}; -initObj["objField"]["newSubPath"] = { - b: valueWithNestedObject -}; -assertAddFieldsResult({"objField.newSubPath.b": valueWithNestedObject}, initObj); -assertAddFieldsResult({"objField.newSubPath.b": {$literal: valueWithNestedObject}}, initObj); -initObj["objField"] = { - p: {q: 1}, - subArr: [1] -}; // Reset input object. - -// When the top level field doesn"t exist, a new nested object is created based on the given path. -initObj["newField"] = { - newSubPath: {b: "newValue"} -}; -assertAddFieldsResult({"newField.newSubPath.b": {$literal: "newValue"}}, initObj); -assertAddFieldsResult({"newField.newSubPath.b": "newValue"}, initObj); - -// When the top level field doesn"t exist, a new nested object is created based on the given path -// and the structure of the object in the value. -initObj["newField"]["newSubPath"] = { - b: valueWithNestedObject -}; -assertAddFieldsResult({"newField.newSubPath.b": valueWithNestedObject}, initObj); -assertAddFieldsResult({"newField.newSubPath.b": {$literal: valueWithNestedObject}}, initObj); -delete initObj["newField"]; // Reset. - -// Test when the path encounters an array and the value is a scalar. -initObj["arrayField"] = { - newSubPath: {b: "newValue"} -}; -let expectedSubObj = {newSubPath: {b: "newValue"}}; -initObj["arrayField"] = - [expectedSubObj, Object.assign({subField: [2, {}]}, expectedSubObj), [expectedSubObj]]; -assertAddFieldsResult({"arrayField.newSubPath.b": {$literal: "newValue"}}, initObj); -assertAddFieldsResult({"arrayField.newSubPath.b": "newValue"}, initObj); - -// Test when the path encounters an array and the value is a nested object. -expectedSubObj = { - newSubPath: {b: valueWithNestedObject} -}; -initObj["arrayField"] = - [expectedSubObj, Object.assign({subField: [2, {}]}, expectedSubObj), [expectedSubObj]]; -assertAddFieldsResult({"arrayField.newSubPath.b": valueWithNestedObject}, initObj); -assertAddFieldsResult({"arrayField.newSubPath.b": {$literal: valueWithNestedObject}}, initObj); - -// Test when the path encounters multiple arrays and the value is a nested object. -expectedSubObj = { - subField: {b: valueWithNestedObject} -}; -initObj["arrayField"] = [ - expectedSubObj, - { - subField: - [{b: valueWithNestedObject}, {b: valueWithNestedObject}] // Sub-array is also exploded. - }, - [expectedSubObj] -]; -assertAddFieldsResult({"arrayField.subField.b": valueWithNestedObject}, initObj); -assertAddFieldsResult({"arrayField.subField.b": {$literal: valueWithNestedObject}}, initObj); -})(); |