summaryrefslogtreecommitdiff
path: root/jstests/sharding/missing_key.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding/missing_key.js')
-rw-r--r--jstests/sharding/missing_key.js31
1 files changed, 15 insertions, 16 deletions
diff --git a/jstests/sharding/missing_key.js b/jstests/sharding/missing_key.js
index 2eebc0d0912..588d85e1a95 100644
--- a/jstests/sharding/missing_key.js
+++ b/jstests/sharding/missing_key.js
@@ -1,40 +1,39 @@
// Test that the shardCollection command fails when a preexisting document lacks a shard key field.
// SERVER-8772
-var st = new ShardingTest( { shards: 1 } );
+var st = new ShardingTest({shards: 1});
st.stopBalancer();
-var db = st.s.getDB( 'testDb' );
+var db = st.s.getDB('testDb');
var coll = db.testColl;
-coll.insert( { x:1, z:1 } );
-coll.insert( { y:1, z:1 } );
-db.adminCommand( { enableSharding:'testDb' } );
+coll.insert({x: 1, z: 1});
+coll.insert({y: 1, z: 1});
+db.adminCommand({enableSharding: 'testDb'});
/**
* Assert that the shardCollection command fails, with a preexisting index on the provided
* 'shardKey'.
*/
-function assertInvalidShardKey( shardKey ) {
-
+function assertInvalidShardKey(shardKey) {
// Manually create a shard key index.
coll.dropIndexes();
- coll.ensureIndex( shardKey );
+ coll.ensureIndex(shardKey);
// Ensure that the shard key index identifies 'x' as present in one document and absent in the
// other.
- assert.eq( 1, coll.find( { x:1 } ).hint( shardKey ).itcount() );
- assert.eq( 1, coll.find( { x:{ $exists:false } } ).hint( shardKey ).itcount() );
+ assert.eq(1, coll.find({x: 1}).hint(shardKey).itcount());
+ assert.eq(1, coll.find({x: {$exists: false}}).hint(shardKey).itcount());
// Assert that the shardCollection command fails with the provided 'shardKey'.
- assert.commandFailed( db.adminCommand( { shardCollection:'testDb.testColl', key:shardKey } ),
- 'shardCollection should have failed on key ' + tojson( shardKey ) );
+ assert.commandFailed(db.adminCommand({shardCollection: 'testDb.testColl', key: shardKey}),
+ 'shardCollection should have failed on key ' + tojson(shardKey));
}
// Test single, compound, and hashed shard keys.
-assertInvalidShardKey( { x:1 } );
-assertInvalidShardKey( { x:1, y:1 } );
-assertInvalidShardKey( { y:1, x:1 } );
-assertInvalidShardKey( { x:'hashed' } );
+assertInvalidShardKey({x: 1});
+assertInvalidShardKey({x: 1, y: 1});
+assertInvalidShardKey({y: 1, x: 1});
+assertInvalidShardKey({x: 'hashed'});
st.stop();