jstests/sharding/timeseries_shard_collection.js
// Shard key on the metadata field and time fields.
Shard key on the metadata field and time fields.
Shard key on the metadata field and time fields .
function metaAndTimeShardKey(implicit) {
        assert.commandWorked(st.s.adminCommand({enableSharding: 'test'}));
        if (!implicit) {
            assert.commandWorked(sDB.createCollection('ts', {timeseries}));
        }
        assert.commandWorked(st.s.adminCommand({
            shardCollection: 'test.ts',
            key: {'hostId': 1, 'time': 1},
            timeseries,
        }));
        validateViewCreated("ts");
        validateBucketsCollectionSharded({
            collName: 'ts',
            shardKey: {meta: 1, 'control.min.time': 1},
            timeseries,
        });
        assert.commandWorked(st.s.adminCommand(
            {split: 'test.system.buckets.ts', middle: {meta: 10, 'control.min.time': MinKey}}));
        const primaryShard = st.getPrimaryShard(dbName);
        assert.commandWorked(st.s.adminCommand({
            movechunk: 'test.system.buckets.ts',
            find: {meta: 10, 'control.min.time': MinKey},
            to: st.getOther(primaryShard).shardName,
            _waitForDelete: true,
        }));
        let counts = st.chunkCounts('system.buckets.ts', 'test');
        assert.eq(1, counts[st.shard0.shardName]);
        assert.eq(1, counts[st.shard1.shardName]);
        assert(sDB.ts.drop());
    }
function metaAndTimeShardKey ( implicit ) { assert . commandWorked ( st . s . adminCommand ( { enableSharding : 'test' } ) ) ; if ( ! implicit ) { assert . commandWorked ( sDB . createCollection ( 'ts' , { timeseries } ) ) ; } assert . commandWorked ( st . s . adminCommand ( { shardCollection : 'test.ts' , key : { 'hostId' : 1 , 'time' : 1 } , timeseries , } ) ) ; validateViewCreated ( "ts" ) ; validateBucketsCollectionSharded ( { collName : 'ts' , shardKey : { meta : 1 , 'control.min.time' : 1 } , timeseries , } ) ; assert . commandWorked ( st . s . adminCommand ( { split : 'test.system.buckets.ts' , middle : { meta : 10 , 'control.min.time' : MinKey } } ) ) ; const primaryShard = st . getPrimaryShard ( dbName ) ; assert . commandWorked ( st . s . adminCommand ( { movechunk : 'test.system.buckets.ts' , find : { meta : 10 , 'control.min.time' : MinKey } , to : st . getOther ( primaryShard ) . shardName , _waitForDelete : true , } ) ) ; let counts = st . chunkCounts ( 'system.buckets.ts' , 'test' ) ; assert . eq ( 1 , counts [ st . shard0 . shardName ] ) ; assert . eq ( 1 , counts [ st . shard1 . shardName ] ) ; assert ( sDB . ts . drop ( ) ) ; }
Shard key on the metadata field and time fields.
Shard key on the metadata field and time fields .
// The 'time' field should be translated to 'control.min.time' on buckets collection.