summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorIan Boros <ian.boros@mongodb.com>2019-10-23 15:15:44 +0000
committerevergreen <evergreen@mongodb.com>2019-10-23 15:15:44 +0000
commit35fbf9bc919f0645b1269cd9916ce2509617e072 (patch)
tree85e3f794a300b74ee39e7a90cb3b6dfe8642fa26 /jstests
parent2070d8ca09576b858c61677bc366a25e7ecfecad (diff)
downloadmongo-35fbf9bc919f0645b1269cd9916ce2509617e072.tar.gz
SERVER-43840 fix invariant failure in exclusion projection parser
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/dbref3.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/jstests/core/dbref3.js b/jstests/core/dbref3.js
index 5bf0470442d..6a91a56da2a 100644
--- a/jstests/core/dbref3.js
+++ b/jstests/core/dbref3.js
@@ -42,4 +42,18 @@ assert.eq(1, distinctDBs.length);
t.insert({sub: {$ref: "foo", $id: [{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}]}});
var k = t.findOne({'sub.$id': {$elemMatch: {x: 2}}}, {_id: 0, 'sub.$id.$': 1});
print('k = ' + tojson(k));
-assert.eq({sub: {$id: [{x: 2, y: 2}]}}, k); \ No newline at end of file
+assert.eq({sub: {$id: [{x: 2, y: 2}]}}, k);
+
+// Check that DBRef fields can be excluded
+assert.commandWorked(
+ t.insert({_id: 0, shouldExclude: 1, sub: {$ref: "foo", $id: 10, $db: "someDb"}}));
+assert.eq(t.find({shouldExclude: 1}, {"sub.$ref": 0}).toArray(),
+ [{_id: 0, shouldExclude: 1, sub: {$id: 10, $db: "someDb"}}]);
+assert.eq(t.find({shouldExclude: 1}, {"sub.$id": 0}).toArray(),
+ [{_id: 0, shouldExclude: 1, sub: {$ref: "foo", $db: "someDb"}}]);
+assert.eq(t.find({shouldExclude: 1}, {"sub.$id": 0, "sub.$ref": 0, "sub.$db": 0}).toArray(),
+ [{_id: 0, shouldExclude: 1, sub: {}}]);
+
+// It should be legal to exclude a DBRef field anywhere, even at the top layer.
+assert.eq(t.aggregate([{$match: {shouldExclude: 1}}, {$project: {"$id": 0, sub: 0}}]).toArray(),
+ [{_id: 0, shouldExclude: 1}]);