summaryrefslogtreecommitdiff
path: root/jstests/query_golden
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/query_golden')
-rw-r--r--jstests/query_golden/elemMatch.js64
-rw-r--r--jstests/query_golden/eq.js2
-rw-r--r--jstests/query_golden/expected_output/elemMatch92
-rw-r--r--jstests/query_golden/match_with_exists.js2
-rw-r--r--jstests/query_golden/match_with_in.js2
5 files changed, 159 insertions, 3 deletions
diff --git a/jstests/query_golden/elemMatch.js b/jstests/query_golden/elemMatch.js
new file mode 100644
index 00000000000..bb6fb526257
--- /dev/null
+++ b/jstests/query_golden/elemMatch.js
@@ -0,0 +1,64 @@
+(function() {
+"use strict";
+
+const coll = db.cqf_elemMatch;
+coll.drop();
+
+jsTestLog('Inserting docs:');
+
+const docs = [
+ {a: [1, 2, 3, 4, 5, 6]},
+ {a: [5, 6, 7, 8, 9]},
+ {a: [1, 2, 3]},
+ {a: []},
+ {a: [1]},
+ {a: [10]},
+ {a: 5},
+ {a: 6},
+ {a: [[6]]},
+ {a: [[[6]]]},
+ {a: [{b: [6]}]},
+ {a: [[{b: [6]}]]},
+];
+show(docs);
+
+assert.commandWorked(coll.insert(docs));
+
+function runPipeline(pipeline) {
+ pipeline.push({$project: {_id: 0}});
+ jsTestLog(`Pipeline: ${tojsononeline(pipeline)}`);
+ show(coll.aggregate(pipeline));
+}
+
+// Value elemMatch.
+let pipeline = [{$match: {a: {$elemMatch: {$gte: 5, $lte: 6}}}}];
+runPipeline(pipeline);
+
+pipeline = [{$match: {a: {$elemMatch: {$lt: 11, $gt: 9}}}}];
+runPipeline(pipeline);
+
+// Contradiction.
+pipeline = [{$match: {a: {$elemMatch: {$lt: 5, $gt: 6}}}}];
+runPipeline(pipeline);
+
+// Nested elemMatch.
+pipeline = [{$match: {a: {$elemMatch: {$elemMatch: {$gte: 5, $lte: 6}}}}}];
+runPipeline(pipeline);
+
+pipeline = [{$match: {a: {$elemMatch: {$elemMatch: {$elemMatch: {$gte: 5, $lte: 6}}}}}}];
+runPipeline(pipeline);
+
+// Various expressions under $elemMatch.
+pipeline = [{$match: {a: {$elemMatch: {$size: 1}}}}];
+runPipeline(pipeline);
+
+pipeline = [{$match: {a: {$elemMatch: {$exists: true}}}}];
+runPipeline(pipeline);
+
+// Test for a value $elemMatch nested under an object $elemMatch.
+pipeline = [{$match: {a: {$elemMatch: {b: {$elemMatch: {$gt: 5}}}}}}];
+runPipeline(pipeline);
+
+pipeline = [{$match: {a: {$elemMatch: {$elemMatch: {b: {$elemMatch: {$gt: 5}}}}}}}];
+runPipeline(pipeline);
+}());
diff --git a/jstests/query_golden/eq.js b/jstests/query_golden/eq.js
index ebc1d922e0d..5847088a1b2 100644
--- a/jstests/query_golden/eq.js
+++ b/jstests/query_golden/eq.js
@@ -14,7 +14,7 @@ let output = '';
jsTestLog('Inserting docs:');
show(docs);
coll.insert(docs);
-print(`Collection count: ${coll.count()}`);
+print(`Collection count: ${coll.find().itcount()}`);
for (const leaf of leafs()) {
// TODO SERVER-67550 Equality to null does not match undefined, in Bonsai.
diff --git a/jstests/query_golden/expected_output/elemMatch b/jstests/query_golden/expected_output/elemMatch
new file mode 100644
index 00000000000..79598e1741e
--- /dev/null
+++ b/jstests/query_golden/expected_output/elemMatch
@@ -0,0 +1,92 @@
+
+
+[jsTest] ----
+[jsTest] Inserting docs:
+[jsTest] ----
+
+{ "a" : 5 }
+{ "a" : 6 }
+{ "a" : [ 1 ] }
+{ "a" : [ 1, 2, 3 ] }
+{ "a" : [ 1, 2, 3, 4, 5, 6 ] }
+{ "a" : [ 10 ] }
+{ "a" : [ 5, 6, 7, 8, 9 ] }
+{ "a" : [ [ 6 ] ] }
+{ "a" : [ [ [ 6 ] ] ] }
+{ "a" : [ [ { "b" : [ 6 ] } ] ] }
+{ "a" : [ ] }
+{ "a" : [ { "b" : [ 6 ] } ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$gte" : 5, "$lte" : 6 } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ 1, 2, 3, 4, 5, 6 ] }
+{ "a" : [ 5, 6, 7, 8, 9 ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$lt" : 11, "$gt" : 9 } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ 10 ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$lt" : 5, "$gt" : 6 } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$elemMatch" : { "$gte" : 5, "$lte" : 6 } } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ [ 6 ] ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$elemMatch" : { "$elemMatch" : { "$gte" : 5, "$lte" : 6 } } } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ [ [ 6 ] ] ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$size" : 1 } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ [ 6 ] ] }
+{ "a" : [ [ [ 6 ] ] ] }
+{ "a" : [ [ { "b" : [ 6 ] } ] ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$exists" : true } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ 1 ] }
+{ "a" : [ 1, 2, 3 ] }
+{ "a" : [ 1, 2, 3, 4, 5, 6 ] }
+{ "a" : [ 10 ] }
+{ "a" : [ 5, 6, 7, 8, 9 ] }
+{ "a" : [ [ 6 ] ] }
+{ "a" : [ [ [ 6 ] ] ] }
+{ "a" : [ [ { "b" : [ 6 ] } ] ] }
+{ "a" : [ { "b" : [ 6 ] } ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "b" : { "$elemMatch" : { "$gt" : 5 } } } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ { "b" : [ 6 ] } ] }
+
+
+[jsTest] ----
+[jsTest] Pipeline: [ { "$match" : { "a" : { "$elemMatch" : { "$elemMatch" : { "b" : { "$elemMatch" : { "$gt" : 5 } } } } } } }, { "$project" : { "_id" : 0 } } ]
+[jsTest] ----
+
+{ "a" : [ [ { "b" : [ 6 ] } ] ] }
diff --git a/jstests/query_golden/match_with_exists.js b/jstests/query_golden/match_with_exists.js
index 6b46cf6df7a..c2f64a1532e 100644
--- a/jstests/query_golden/match_with_exists.js
+++ b/jstests/query_golden/match_with_exists.js
@@ -18,7 +18,7 @@ const runWithData = (docs, filters) => {
jsTestLog("Inserting docs:");
show(docs);
assert.commandWorked(coll.insert(docs));
- print(`Collection count: ${coll.count()}`);
+ print(`Collection count: ${coll.find().itcount()}`);
for (const filter of filters) {
runTest(filter);
}
diff --git a/jstests/query_golden/match_with_in.js b/jstests/query_golden/match_with_in.js
index b87073d6789..849468aec21 100644
--- a/jstests/query_golden/match_with_in.js
+++ b/jstests/query_golden/match_with_in.js
@@ -28,7 +28,7 @@ const docs = [
jsTestLog('Inserting docs:');
show(docs);
assert.commandWorked(coll.insert(docs));
-print(`Collection count: ${coll.count()}`);
+print(`Collection count: ${coll.find().itcount()}`);
const runTest = (filter) => {
const pipeline = [{$match: filter}];