diff options
author | Alya Berciu <alyacarina@gmail.com> | 2021-05-10 13:47:12 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-11 11:00:40 +0000 |
commit | 75818543f75a16f9dc5711ae5ffdc6ce67f156b5 (patch) | |
tree | 0739bfd751e6153850c216b2aeeb73cf15a56e29 /jstests/core | |
parent | 53b252b212696c6ad85508f6db9e51724296fcd1 (diff) | |
download | mongo-75818543f75a16f9dc5711ae5ffdc6ce67f156b5.tar.gz |
SERVER-49474 Test '.' fieldname storage validation for findAndModify
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/field_name_validation.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/jstests/core/field_name_validation.js b/jstests/core/field_name_validation.js index 31ca9ccc5e0..936da4147de 100644 --- a/jstests/core/field_name_validation.js +++ b/jstests/core/field_name_validation.js @@ -178,6 +178,22 @@ assert.eq([{_id: 0, "a.b": 1}], coll.find({_id: 0}).toArray()); coll.findAndModify({query: {_id: 1, "a.b": 1}, update: {$set: {_id: 1, "a.b": 2}}}); assert.eq([{_id: 1, a: {b: 2}}], coll.find({_id: 1}).toArray()); +// Dotted fields in a $literal-wrapped document can be updated in a pipeline-style update. +coll.findAndModify({query: {_id: 1}, update: [{$replaceWith: {$literal: {_id: 1, "a.b": 3}}}]}); +assert.eq([{_id: 1, "a.b": 3}], coll.find({_id: 1}).toArray()); + +coll.findAndModify({query: {_id: 1}, update: [{$replaceWith: {$literal: {_id: 1, "a.b.c": 3}}}]}); +assert.eq([{_id: 1, "a.b.c": 3}], coll.find({_id: 1}).toArray()); + +// Dotted fields without $literal cannot be updated in a pipeline-style update. +assert.throws(function() { + coll.findAndModify({query: {_id: 1}, update: [{$replaceWith: {_id: 1, "a.b.": 2}}]}); +}); + +assert.throws(function() { + coll.findAndModify({query: {_id: 1}, update: [{$replaceWith: {_id: 1, "a.b.c": 3}}]}); +}); + if (isDotsAndDollarsEnabled) { // Top-level $-prefixed field names are not allowed in a replacement-style update. assert.throws(function() { |