summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorAnne Lim <anne.lim@mongodb.com>2017-08-02 09:48:19 -0400
committerAnne Lim <anne.lim@mongodb.com>2017-08-02 09:48:19 -0400
commitb66d485345c99c8877f2d0bc72a4f123de720cb0 (patch)
tree31844a3949fd1c900b3f7e93929faea1671b0c9b /jstests
parent0deaa0f0ec0f659afcf39144e9dc0b60ec464ea8 (diff)
downloadmongo-b66d485345c99c8877f2d0bc72a4f123de720cb0.tar.gz
Revert "scalars part 2"
This reverts commit 0deaa0f0ec0f659afcf39144e9dc0b60ec464ea8.
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/json_schema.js80
1 files changed, 11 insertions, 69 deletions
diff --git a/jstests/core/json_schema.js b/jstests/core/json_schema.js
index 47f7ea26911..bfebfb7ab90 100644
--- a/jstests/core/json_schema.js
+++ b/jstests/core/json_schema.js
@@ -12,8 +12,7 @@
assert.writeOK(coll.insert({_id: 5, num: NumberLong(-1)}));
assert.writeOK(coll.insert({_id: 6, num: {}}));
assert.writeOK(coll.insert({_id: 7, num: "str"}));
- assert.writeOK(coll.insert({_id: 8, num: "string"}));
- assert.writeOK(coll.insert({_id: 9}));
+ assert.writeOK(coll.insert({_id: 8}));
// Test that $jsonSchema fails to parse if its argument is not an object.
assert.throws(function() {
@@ -46,33 +45,20 @@
coll.find({$jsonSchema: {properties: {num: "number"}}}).itcount();
});
- // Test that $jsonSchema fails to parse if the values for the maximum, maxLength, and
- // minlength keywords are not numbers.
+ // Test that $jsonSchema fails to parse if the value for the maximum keyword is not a number.
assert.throws(function() {
coll.find({$jsonSchema: {properties: {num: {maximum: "0"}}}}).itcount();
});
assert.throws(function() {
coll.find({$jsonSchema: {properties: {num: {maximum: {}}}}}).itcount();
});
- assert.throws(function() {
- coll.find({$jsonSchema: {properties: {num: {maxLength: "0"}}}}).itcount();
- });
- assert.throws(function() {
- coll.find({$jsonSchema: {properties: {num: {maxLength: {}}}}}).itcount();
- });
- assert.throws(function() {
- coll.find({$jsonSchema: {properties: {num: {minLength: "0"}}}}).itcount();
- });
- assert.throws(function() {
- coll.find({$jsonSchema: {properties: {num: {minLength: {}}}}}).itcount();
- });
// Test that the empty schema matches everything.
- assert.eq(10, coll.find({$jsonSchema: {}}).itcount());
+ assert.eq(9, coll.find({$jsonSchema: {}}).itcount());
// Test that a schema just checking that the type of stored documents is "object" is legal and
// matches everything.
- assert.eq(10, coll.find({$jsonSchema: {type: "object"}}).itcount());
+ assert.eq(9, coll.find({$jsonSchema: {type: "object"}}).itcount());
// Test that schemas whose top-level type is not object matches nothing.
assert.eq(0, coll.find({$jsonSchema: {type: "string"}}).itcount());
@@ -80,93 +66,49 @@
assert.eq(0, coll.find({$jsonSchema: {type: "objectId"}}).itcount());
// Test that type:"number" only matches numbers, or documents where the field is missing.
- assert.eq([{_id: 0}, {_id: 1}, {_id: 2}, {_id: 3}, {_id: 4}, {_id: 5}, {_id: 9}],
+ assert.eq([{_id: 0}, {_id: 1}, {_id: 2}, {_id: 3}, {_id: 4}, {_id: 5}, {_id: 8}],
coll.find({$jsonSchema: {properties: {num: {type: "number"}}}}, {_id: 1})
.sort({_id: 1})
.toArray());
// Test that maximum restriction is enforced correctly.
- assert.eq([{_id: 1}, {_id: 3}, {_id: 5}, {_id: 9}],
+ assert.eq([{_id: 1}, {_id: 3}, {_id: 5}, {_id: 8}],
coll.find({$jsonSchema: {properties: {num: {type: "number", maximum: -1}}}}, {_id: 1})
.sort({_id: 1})
.toArray());
// Repeat the test, but include an explicit top-level type:"object".
assert.eq(
- [{_id: 1}, {_id: 3}, {_id: 5}, {_id: 9}],
+ [{_id: 1}, {_id: 3}, {_id: 5}, {_id: 8}],
coll.find({$jsonSchema: {type: "object", properties: {num: {type: "number", maximum: -1}}}},
{_id: 1})
.sort({_id: 1})
.toArray());
// Test that type:"long" only matches longs, or documents where the field is missing.
- assert.eq([{_id: 4}, {_id: 5}, {_id: 9}],
+ assert.eq([{_id: 4}, {_id: 5}, {_id: 8}],
coll.find({$jsonSchema: {properties: {num: {type: "long"}}}}, {_id: 1})
.sort({_id: 1})
.toArray());
// Test that maximum restriction is enforced correctly with type:"long".
- assert.eq([{_id: 5}, {_id: 9}],
+ assert.eq([{_id: 5}, {_id: 8}],
coll.find({$jsonSchema: {properties: {num: {type: "long", maximum: 0}}}}, {_id: 1})
.sort({_id: 1})
.toArray());
// Test that maximum restriction without a numeric type specified only applies to numbers.
- assert.eq([{_id: 1}, {_id: 3}, {_id: 5}, {_id: 6}, {_id: 7}, {_id: 8}, {_id: 9}],
+ assert.eq([{_id: 1}, {_id: 3}, {_id: 5}, {_id: 6}, {_id: 7}, {_id: 8}],
coll.find({$jsonSchema: {properties: {num: {maximum: 0}}}}, {_id: 1})
.sort({_id: 1})
.toArray());
// Test that maximum restriction does nothing if a non-numeric type is also specified.
- assert.eq([{_id: 7}, {_id: 8}, {_id: 9}],
+ assert.eq([{_id: 7}, {_id: 8}],
coll.find({$jsonSchema: {properties: {num: {type: "string", maximum: 0}}}}, {_id: 1})
.sort({_id: 1})
.toArray());
- // Test that maxLength restriction doesn't return strings with length greater than maxLength.
- assert.eq(
- [{_id: 9}],
- coll.find({$jsonSchema: {properties: {num: {type: "string", maxLength: 2}}}}, {_id: 1})
- .sort({_id: 1})
- .toArray());
-
- // Test that maxLength restriction returns strings with length less than or equal to maxLength.
- assert.eq(
- [{_id: 7}, {_id: 9}],
- coll.find({$jsonSchema: {properties: {num: {type: "string", maxLength: 3}}}}, {_id: 1})
- .sort({_id: 1})
- .toArray());
-
- // Test that minLength restriction doesn't return strings with length less than minLength.
- assert.eq(
- [{_id: 8}, {_id: 9}],
- coll.find({$jsonSchema: {properties: {num: {type: "string", minLength: 4}}}}, {_id: 1})
- .sort({_id: 1})
- .toArray());
-
- // Test that minLength restriction returns strings with length greater than or equal to
- // minLength.
- assert.eq(
- [{_id: 7}, {_id: 8}, {_id: 9}],
- coll.find({$jsonSchema: {properties: {num: {type: "string", minLength: 3}}}}, {_id: 1})
- .sort({_id: 1})
- .toArray());
-
- // Test that $jsonSchema fails to parse if the values for the pattern keyword is not a string.
- assert.throws(function() {
- coll.find({$jsonSchema: {properties: {num: {pattern: 0}}}}).itcount();
- });
- assert.throws(function() {
- coll.find({$jsonSchema: {properties: {num: {pattern: {}}}}}).itcount();
- });
-
- // Tests that the pattern keyword only returns strings that match the regex pattern.
- assert.eq(
- [{_id: 8}, {_id: 9}],
- coll.find({$jsonSchema: {properties: {num: {type: "string", pattern: "ing"}}}}, {_id: 1})
- .sort({_id: 1})
- .toArray());
-
coll.drop();
assert.writeOK(coll.insert({_id: 0, obj: 3}));
assert.writeOK(coll.insert({_id: 1, obj: {f1: {f3: "str"}, f2: "str"}}));