diff options
author | clang-format-7.0.1 <adam.martin@10gen.com> | 2019-07-26 18:20:35 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-07-27 11:02:23 -0400 |
commit | 134a4083953270e8a11430395357fb70a29047ad (patch) | |
tree | dd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /jstests/sharding/json_schema.js | |
parent | 1e46b5049003f427047e723ea5fab15b5a9253ca (diff) | |
download | mongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz |
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'jstests/sharding/json_schema.js')
-rw-r--r-- | jstests/sharding/json_schema.js | 117 |
1 files changed, 60 insertions, 57 deletions
diff --git a/jstests/sharding/json_schema.js b/jstests/sharding/json_schema.js index 1c24f427eed..5a4a68102b7 100644 --- a/jstests/sharding/json_schema.js +++ b/jstests/sharding/json_schema.js @@ -2,61 +2,64 @@ * Tests for $jsonSchema queries in a sharded cluster. */ (function() { - "use strict"; - - const dbName = "json_schema_sharding"; - - var st = new ShardingTest({shards: 2, mongos: 1, config: 1}); - - assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); - st.ensurePrimaryShard(dbName, st.shard0.name); - - const testDB = st.s.getDB(dbName); - const coll = testDB.json_schema_sharding; - coll.drop(); - - // Shard the collection on _id. - assert.commandWorked(testDB.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}})); - - // Split the collection into 4 chunks: [MinKey, -100), [-100, 0), [0, 100), [100, MaxKey). - assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {_id: -100}})); - assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {_id: 0}})); - assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {_id: 100}})); - - // Move the [0, 100) and [100, MaxKey) chunks to st.shard1.shardName. - assert.commandWorked(testDB.adminCommand( - {moveChunk: coll.getFullName(), find: {_id: 50}, to: st.shard1.shardName})); - assert.commandWorked(testDB.adminCommand( - {moveChunk: coll.getFullName(), find: {_id: 150}, to: st.shard1.shardName})); - - // Write one document into each of the chunks. - assert.writeOK(coll.insert({_id: -150, a: 1})); - assert.writeOK(coll.insert({_id: -50, a: 10})); - assert.writeOK(coll.insert({_id: 50, a: "str"})); - assert.writeOK(coll.insert({_id: 150})); - - // Test that $jsonSchema in a find command returns the correct results. - assert.eq(4, coll.find({$jsonSchema: {}}).itcount()); - assert.eq(3, coll.find({$jsonSchema: {properties: {a: {type: "number"}}}}).itcount()); - assert.eq(4, coll.find({$jsonSchema: {required: ["_id"]}}).itcount()); - assert.eq(1, coll.find({$jsonSchema: {properties: {_id: {minimum: 150}}}}).itcount()); - - // Test that $jsonSchema works correctly in an update command. - let res = coll.update( - {$jsonSchema: {properties: {_id: {type: "number", minimum: 100}, a: {type: "number"}}}}, - {$inc: {a: 1}}, - {multi: true}); - assert.writeOK(res); - assert.eq(1, res.nModified); - - const schema = {properties: {_id: {type: "number", minimum: 100}}, required: ["_id"]}; - res = coll.update({$jsonSchema: schema}, {$set: {b: 1}}, {multi: true}); - assert.writeOK(res); - assert.eq(1, res.nModified); - - // Test that $jsonSchema works correctly in a findAndModify command. - res = coll.findAndModify({query: {_id: 150, $jsonSchema: schema}, update: {$set: {b: 1}}}); - assert.eq(1, res.b); - - st.stop(); +"use strict"; + +const dbName = "json_schema_sharding"; + +var st = new ShardingTest({shards: 2, mongos: 1, config: 1}); + +assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); +st.ensurePrimaryShard(dbName, st.shard0.name); + +const testDB = st.s.getDB(dbName); +const coll = testDB.json_schema_sharding; +coll.drop(); + +// Shard the collection on _id. +assert.commandWorked(testDB.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}})); + +// Split the collection into 4 chunks: [MinKey, -100), [-100, 0), [0, 100), [100, MaxKey). +assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {_id: -100}})); +assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {_id: 0}})); +assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {_id: 100}})); + +// Move the [0, 100) and [100, MaxKey) chunks to st.shard1.shardName. +assert.commandWorked( + testDB.adminCommand({moveChunk: coll.getFullName(), find: {_id: 50}, to: st.shard1.shardName})); +assert.commandWorked(testDB.adminCommand( + {moveChunk: coll.getFullName(), find: {_id: 150}, to: st.shard1.shardName})); + +// Write one document into each of the chunks. +assert.writeOK(coll.insert({_id: -150, a: 1})); +assert.writeOK(coll.insert({_id: -50, a: 10})); +assert.writeOK(coll.insert({_id: 50, a: "str"})); +assert.writeOK(coll.insert({_id: 150})); + +// Test that $jsonSchema in a find command returns the correct results. +assert.eq(4, coll.find({$jsonSchema: {}}).itcount()); +assert.eq(3, coll.find({$jsonSchema: {properties: {a: {type: "number"}}}}).itcount()); +assert.eq(4, coll.find({$jsonSchema: {required: ["_id"]}}).itcount()); +assert.eq(1, coll.find({$jsonSchema: {properties: {_id: {minimum: 150}}}}).itcount()); + +// Test that $jsonSchema works correctly in an update command. +let res = coll.update( + {$jsonSchema: {properties: {_id: {type: "number", minimum: 100}, a: {type: "number"}}}}, + {$inc: {a: 1}}, + {multi: true}); +assert.writeOK(res); +assert.eq(1, res.nModified); + +const schema = { + properties: {_id: {type: "number", minimum: 100}}, + required: ["_id"] +}; +res = coll.update({$jsonSchema: schema}, {$set: {b: 1}}, {multi: true}); +assert.writeOK(res); +assert.eq(1, res.nModified); + +// Test that $jsonSchema works correctly in a findAndModify command. +res = coll.findAndModify({query: {_id: 150, $jsonSchema: schema}, update: {$set: {b: 1}}}); +assert.eq(1, res.b); + +st.stop(); })(); |