diff options
Diffstat (limited to 'jstests/core/null_query_semantics.js')
| -rw-r--r-- | jstests/core/null_query_semantics.js | 164 |
1 files changed, 44 insertions, 120 deletions
diff --git a/jstests/core/null_query_semantics.js b/jstests/core/null_query_semantics.js index aa9042c5ac5..1ff14cc710c 100644 --- a/jstests/core/null_query_semantics.js +++ b/jstests/core/null_query_semantics.js @@ -41,9 +41,6 @@ function testNullSemantics(coll) { [{_id: "a_null", a: null}, {_id: "a_undefined", a: undefined}, {_id: "no_a"}]; assert(resultsEq(expected, noProjectResults), tojson(noProjectResults)); - const count = coll.count({a: {$eq: null}}); - assert.eq(count, expected.length); - const projectResults = coll.find({a: {$eq: null}}, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), tojson(projectResults)); }()); @@ -60,9 +57,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count({a: {$ne: null}}); - assert.eq(count, expected.length); - const projectResults = coll.find({a: {$ne: null}}, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), tojson(projectResults)); }()); @@ -78,9 +72,6 @@ function testNullSemantics(coll) { {_id: "no_a"}, ]; - const count = coll.count(query); - assert.eq(count, expected.length); - assert(resultsEq(noProjectResults, expected), noProjectResults); const projectResults = coll.find(query, projectToOnlyA).toArray(); @@ -98,9 +89,6 @@ function testNullSemantics(coll) { {_id: "no_a"}, ]; - const count = coll.count(query); - assert.eq(count, expected.length); - assert(resultsEq(noProjectResults, expected), noProjectResults); const projectResults = coll.find(query, projectToOnlyA).toArray(); @@ -118,9 +106,6 @@ function testNullSemantics(coll) { {_id: "a_subobject_b_undefined", a: {b: undefined}}, ]; - const count = coll.count(query); - assert.eq(count, expected.length); - assert(resultsEq(noProjectResults, expected), noProjectResults); const projectResults = coll.find(query, projectToOnlyA).toArray(); @@ -141,9 +126,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count(query); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -155,9 +137,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count({a: {$exists: false}}); - assert.eq(count, expected.length); - const projectResults = coll.find({a: {$exists: false}}, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), tojson(projectResults)); }()); @@ -165,19 +144,17 @@ function testNullSemantics(coll) { // Test the semantics of the query {"a.b": {$eq: null}}. (function testDottedEqualsNull() { const noProjectResults = coll.find({"a.b": {$eq: null}}).toArray(); - const expected = [ - {_id: "a_empty_subobject", a: {}}, - {_id: "a_null", a: null}, - {_id: "a_number", a: 4}, - {_id: "a_subobject_b_null", a: {b: null}}, - {_id: "a_subobject_b_undefined", a: {b: undefined}}, - {_id: "a_undefined", a: undefined}, - {_id: "no_a"} - ]; - assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - - const count = coll.count({"a.b": {$eq: null}}); - assert.eq(count, expected.length); + assert(resultsEq(noProjectResults, + [ + {_id: "a_empty_subobject", a: {}}, + {_id: "a_null", a: null}, + {_id: "a_number", a: 4}, + {_id: "a_subobject_b_null", a: {b: null}}, + {_id: "a_subobject_b_undefined", a: {b: undefined}}, + {_id: "a_undefined", a: undefined}, + {_id: "no_a"} + ]), + tojson(noProjectResults)); const projectResults = coll.find({"a.b": {$eq: null}}, projectToOnlyADotB).toArray(); assert(resultsEq(projectResults, @@ -188,11 +165,8 @@ function testNullSemantics(coll) { // Test the semantics of the query {"a.b": {$ne: null}}. (function testDottedNotEqualsNull() { const noProjectResults = coll.find({"a.b": {$ne: null}}).toArray(); - const expected = [{_id: "a_subobject_b_not_null", a: {b: "hi"}}]; - assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - - const count = coll.count({"a.b": {$ne: null}}); - assert.eq(count, expected.length); + assert(resultsEq(noProjectResults, [{_id: "a_subobject_b_not_null", a: {b: "hi"}}]), + tojson(noProjectResults)); const projectResults = coll.find({"a.b": {$ne: null}}, projectToOnlyADotB).toArray(); assert(resultsEq(projectResults, [{a: {b: "hi"}}]), tojson(projectResults)); @@ -209,9 +183,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count({"a.b": {$exists: false}}); - assert.eq(count, expected.length); - const projectResults = coll.find({"a.b": {$exists: false}}, projectToOnlyADotB).toArray(); assert(resultsEq(projectResults, [{}, {a: {}}, {}, {}, {}]), tojson(projectResults)); }()); @@ -231,9 +202,6 @@ function testNullSemantics(coll) { `Expected no results for query ${tojson(elemMatchQuery)}, got ` + tojson(noProjectResults)); - const count = coll.count(elemMatchQuery); - assert.eq(count, 0); - let projectResults = coll.find(elemMatchQuery, projectToOnlyA).toArray(); assert(resultsEq(projectResults, []), `Expected no results for query ${tojson(elemMatchQuery)}, got ` + @@ -282,9 +250,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count({a: {$eq: null}}); - assert.eq(count, expected.length); - const projectResults = coll.find({a: {$eq: null}}, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), tojson(projectResults)); }()); @@ -309,9 +274,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count({a: {$ne: null}}); - assert.eq(count, expected.length); - const projectResults = coll.find({a: {$ne: null}}, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), tojson(projectResults)); }()); @@ -335,8 +297,6 @@ function testNullSemantics(coll) { {_id: "a_value_array_no_nulls", a: [1, "string", 4]}, ]; assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - const count = coll.count({a: {$not: {$gte: null}}}); - assert.eq(count, expected.length); }()); // Test the semantics of the query {a: {$in: [null, <number>]}}. @@ -354,9 +314,6 @@ function testNullSemantics(coll) { assert(resultsEq(noProjectResults, expected), noProjectResults); - const count = coll.count({a: {$in: [null, 75]}}); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -376,9 +333,6 @@ function testNullSemantics(coll) { assert(resultsEq(noProjectResults, expected), noProjectResults); - const count = coll.count({$or: [{a: null}, {a: 75}]}); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -406,9 +360,6 @@ function testNullSemantics(coll) { assert(resultsEq(noProjectResults, expected), noProjectResults); - const count = coll.count({a: {$nin: [null, 75]}}); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -444,9 +395,6 @@ function testNullSemantics(coll) { assert(resultsEq(noProjectResults, expected), noProjectResults); - const count = coll.count({a: {$nin: [null, []]}}); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -472,9 +420,6 @@ function testNullSemantics(coll) { assert(resultsEq(noProjectResults, expected), noProjectResults); - const count = coll.count(query); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -490,9 +435,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expectedEqualToNull), tojson(noProjectResults)); - const count = coll.count({a: {$elemMatch: {$eq: null}}}); - assert.eq(count, expectedEqualToNull.length); - let projectResults = coll.find({a: {$elemMatch: {$eq: null}}}, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expectedEqualToNull)), tojson(projectResults)); @@ -525,23 +467,25 @@ function testNullSemantics(coll) { // value for "b". (function testDottedEqualsNull() { const noProjectResults = coll.find({"a.b": {$eq: null}}).toArray(); - const expected = [ - {_id: "a_empty_subobject", a: {}}, - {_id: "a_null", a: null}, - {_id: "a_number", a: 4}, - {_id: "a_subobject_b_null", a: {b: null}}, - {_id: "a_subobject_b_undefined", a: {b: undefined}}, - {_id: "a_undefined", a: undefined}, - {_id: "no_a"}, - {_id: "a_object_array_all_b_nulls", a: [{b: null}, {b: undefined}, {b: null}, {}]}, - {_id: "a_object_array_some_b_nulls", a: [{b: null}, {b: 3}, {b: null}]}, - {_id: "a_object_array_some_b_undefined", a: [{b: undefined}, {b: 3}]}, - {_id: "a_object_array_some_b_missing", a: [{b: 3}, {}]}, - ]; - assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - - const count = coll.count({"a.b": {$eq: null}}); - assert.eq(count, expected.length); + assert( + resultsEq(noProjectResults, + [ + {_id: "a_empty_subobject", a: {}}, + {_id: "a_null", a: null}, + {_id: "a_number", a: 4}, + {_id: "a_subobject_b_null", a: {b: null}}, + {_id: "a_subobject_b_undefined", a: {b: undefined}}, + {_id: "a_undefined", a: undefined}, + {_id: "no_a"}, + { + _id: "a_object_array_all_b_nulls", + a: [{b: null}, {b: undefined}, {b: null}, {}] + }, + {_id: "a_object_array_some_b_nulls", a: [{b: null}, {b: 3}, {b: null}]}, + {_id: "a_object_array_some_b_undefined", a: [{b: undefined}, {b: 3}]}, + {_id: "a_object_array_some_b_missing", a: [{b: 3}, {}]}, + ]), + tojson(noProjectResults)); const projectResults = coll.find({"a.b": {$eq: null}}, projectToOnlyADotB).toArray(); assert(resultsEq(projectResults, @@ -564,20 +508,18 @@ function testNullSemantics(coll) { // Test the semantics of the query {"a.b": {$ne: null}}. (function testDottedNotEqualsNull() { const noProjectResults = coll.find({"a.b": {$ne: null}}).toArray(); - const expected = [ - {_id: "a_subobject_b_not_null", a: {b: "hi"}}, - {_id: "a_double_array", a: [[]]}, - {_id: "a_empty_array", a: []}, - {_id: "a_object_array_no_b_nulls", a: [{b: 1}, {b: 3}, {b: "string"}]}, - {_id: "a_value_array_all_nulls", a: [null, null]}, - {_id: "a_value_array_no_nulls", a: [1, "string", 4]}, - {_id: "a_value_array_with_null", a: [1, "string", null, 4]}, - {_id: "a_value_array_with_undefined", a: [1, "string", undefined, 4]} - ]; - assert(resultsEq(noProjectResults, expected), tojson(noProjectResults)); - - const count = coll.count({"a.b": {$ne: null}}); - assert.eq(count, expected.length); + assert(resultsEq(noProjectResults, + [ + {_id: "a_subobject_b_not_null", a: {b: "hi"}}, + {_id: "a_double_array", a: [[]]}, + {_id: "a_empty_array", a: []}, + {_id: "a_object_array_no_b_nulls", a: [{b: 1}, {b: 3}, {b: "string"}]}, + {_id: "a_value_array_all_nulls", a: [null, null]}, + {_id: "a_value_array_no_nulls", a: [1, "string", 4]}, + {_id: "a_value_array_with_null", a: [1, "string", null, 4]}, + {_id: "a_value_array_with_undefined", a: [1, "string", undefined, 4]} + ]), + tojson(noProjectResults)); const projectResults = coll.find({"a.b": {$ne: null}}, projectToOnlyADotB).toArray(); assert(resultsEq(projectResults, @@ -612,9 +554,6 @@ function testNullSemantics(coll) { {_id: "a_object_array_some_b_missing", a: [{b: 3}, {}]}, ]; - const count = coll.count({"a.b": {$in: [null, 75]}}); - assert.eq(count, expected.length); - assert(resultsEq(noProjectResults, expected), noProjectResults); }()); @@ -636,9 +575,6 @@ function testNullSemantics(coll) { {_id: "a_object_array_some_b_missing", a: [{b: 3}, {}]}, ]; - const count = coll.count({$or: [{"a.b": null}, {"a.b": 75}]}); - assert.eq(count, expected.length); - assert(resultsEq(noProjectResults, expected), noProjectResults); }()); @@ -659,9 +595,6 @@ function testNullSemantics(coll) { assert(resultsEq(noProjectResults, expected), noProjectResults); - const count = coll.count({"a.b": {$nin: [null, 75]}}); - assert.eq(count, expected.length); - const projectResults = coll.find(query, projectToOnlyA).toArray(); assert(resultsEq(projectResults, extractAValues(expected)), projectResults); }()); @@ -680,9 +613,6 @@ function testNullSemantics(coll) { {_id: "a_value_array_with_undefined", a: [1, "string", undefined, 4]}, ]; - const count = coll.count({"a.b": {$nin: [null, /^str.*/]}}); - assert.eq(count, expected.length); - assert(resultsEq(noProjectResults, expected), noProjectResults); const projectResults = coll.find(query, projectToOnlyA).toArray(); @@ -695,9 +625,6 @@ function testNullSemantics(coll) { let results = coll.find({"a.b": {$elemMatch: {$eq: null}}}).toArray(); assert(resultsEq(results, []), tojson(results)); - const count = coll.count({"a.b": {$elemMatch: {$eq: null}}}); - assert.eq(count, 0); - results = coll.find({"a.b": {$elemMatch: {$ne: null}}}).toArray(); assert(resultsEq(results, []), tojson(results)); }()); @@ -715,9 +642,6 @@ function testNullSemantics(coll) { ]; assert(resultsEq(noProjectResults, expectedEqualToNull), tojson(noProjectResults)); - const count = coll.count({a: {$elemMatch: {b: {$eq: null}}}}); - assert.eq(count, expectedEqualToNull.length); - let projectResults = coll.find({a: {$elemMatch: {b: {$eq: null}}}}, projectToOnlyADotB).toArray(); assert(resultsEq(projectResults, |
