summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorIan Boros <puppyofkosh@gmail.com>2019-04-18 17:07:17 -0400
committerIan Boros <puppyofkosh@gmail.com>2019-06-13 16:22:00 -0400
commit013537d55cbde2952f1287e819990235f7282806 (patch)
treedad07598bb99f0523858e52b13dbebafa064040a /jstests
parent28b3f07cc9774f89fbbce0ea434fba102bdabf31 (diff)
downloadmongo-013537d55cbde2952f1287e819990235f7282806.tar.gz
SERVER-40134 fix bug in distinct() against views
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/views/views_distinct.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/jstests/core/views/views_distinct.js b/jstests/core/views/views_distinct.js
index 0a0b6002b15..29ddcdc5269 100644
--- a/jstests/core/views/views_distinct.js
+++ b/jstests/core/views/views_distinct.js
@@ -95,7 +95,10 @@
allDocuments = [];
allDocuments.push({a: 1, b: [2, 3, [4, 5], {c: 6}], d: {e: [1, 2]}});
allDocuments.push({a: [1], b: [2, 3, 4, [5]], c: 6, d: {e: 1}});
- allDocuments.push({a: [1, 2], b: 3, c: [6], d: [{e: 1}, {e: [1, 2]}]});
+ allDocuments.push({a: [[1]], b: [2, 3, [4], [5]], c: 6, d: [[{e: 1}]]});
+ allDocuments.push({a: [[1]], b: [2, 3, [4], [5]], c: 6, d: [{e: {f: 1}}]});
+ allDocuments.push({a: [[1]], b: [2, 3, [4], [5]], c: 6, d: {e: [[{f: 1}]]}});
+ allDocuments.push({a: [1, 2], b: 3, c: [6], d: [{e: 1}, {e: [1, 2]}, {e: {someObject: 1}}]});
allDocuments.push({a: [1, 2], b: [4, 5], c: [undefined], d: [1]});
allDocuments.push({a: null, b: [4, 5, null, undefined], c: [], d: {e: null}});
allDocuments.push({a: undefined, b: null, c: [null], d: {e: undefined}});
@@ -111,4 +114,29 @@
assertIdentityViewDistinctMatchesCollection("c");
assertIdentityViewDistinctMatchesCollection("d");
assertIdentityViewDistinctMatchesCollection("e");
+ assertIdentityViewDistinctMatchesCollection("d.e");
+ assertIdentityViewDistinctMatchesCollection("d.e.f");
+
+ // Test distinct on a deeply nested object through arrays.
+ coll.drop();
+ assert.commandWorked(coll.insert({
+ a: [
+ {b: [{c: [{d: 1}]}]},
+ {b: {c: "not leaf"}},
+ {b: {c: [{d: 2, "not leaf": "not leaf"}]}},
+ {b: [{c: {d: 3}}]},
+ {b: {c: {d: 4}}, "not leaf": "not leaf"},
+ "not leaf",
+ // The documents below should not get traversed by the distinct() because of the
+ // doubly-nested arrays.
+ [[{b: {c: {d: "not leaf"}}}]],
+ [{b: {c: [[{d: "not leaf"}]]}}],
+ ]
+ }));
+ assert.commandWorked(coll.insert({a: "not leaf"}));
+ assertIdentityViewDistinctMatchesCollection("a");
+ assertIdentityViewDistinctMatchesCollection("a.b");
+ assertIdentityViewDistinctMatchesCollection("a.b.c");
+ assertIdentityViewDistinctMatchesCollection("a.b.c.d");
+
}());