summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorIan Boros <puppyofkosh@gmail.com>2019-04-18 17:07:17 -0400
committerIan Boros <puppyofkosh@gmail.com>2019-07-05 13:12:21 -0400
commit5425869f3612ea31c276221e920a60b8933f1a77 (patch)
treeee7b26bed4fbbc48d794b7544ec4a200fde6d448 /jstests/core
parent55062d72da95ff15d0524778dd72922988a33faa (diff)
downloadmongo-5425869f3612ea31c276221e920a60b8933f1a77.tar.gz
SERVER-40134 fix bug in distinct() against views
Diffstat (limited to 'jstests/core')
-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..9f0ce1bdba3 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.writeOK(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.writeOK(coll.insert({a: "not leaf"}));
+ assertIdentityViewDistinctMatchesCollection("a");
+ assertIdentityViewDistinctMatchesCollection("a.b");
+ assertIdentityViewDistinctMatchesCollection("a.b.c");
+ assertIdentityViewDistinctMatchesCollection("a.b.c.d");
+
}());