diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index ad2abce97..bb857cf9a 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -1823,7 +1823,7 @@ describe('Shard', function () { expect(reshardCollectionStub.firstCall.args).to.deep.equal([ 'db.coll', { key: 1 }, - { numInitialChunks: 1000, forceRedistribution: true }, + { forceRedistribution: true }, ]); }); @@ -1860,6 +1860,81 @@ describe('Shard', function () { { numInitialChunks: 1, forceRedistribution: true }, ]); }); + + it('allows user to pass collation', async function () { + const expectedResult = { ok: 1 }; + + const shardCollectionStub = sinon + .stub(shard, 'shardCollection') + .resolves(expectedResult); + const reshardCollectionStub = sinon + .stub(shard, 'reshardCollection') + .resolves(expectedResult); + + await shard.shardAndDistributeCollection('db.coll', { key: 1 }, true, { + collation: { locale: 'simple' }, + }); + + expect(shardCollectionStub.calledOnce).to.equal(true); + expect(shardCollectionStub.firstCall.args).to.deep.equal([ + 'db.coll', + { + key: 1, + }, + true, + { + collation: { locale: 'simple' }, + }, + ]); + + expect(reshardCollectionStub.calledOnce).to.equal(true); + expect(reshardCollectionStub.firstCall.args).to.deep.equal([ + 'db.coll', + { key: 1 }, + { collation: { locale: 'simple' }, forceRedistribution: true }, + ]); + }); + + it('allows user to pass shard-specific options and ignores them when resharding', async function () { + const expectedResult = { ok: 1 }; + + const shardCollectionStub = sinon + .stub(shard, 'shardCollection') + .resolves(expectedResult); + const reshardCollectionStub = sinon + .stub(shard, 'reshardCollection') + .resolves(expectedResult); + + await shard.shardAndDistributeCollection('db.coll', { key: 1 }, true, { + presplitHashedZones: true, + timeseries: { + timeField: 'ts', + }, + }); + + expect(shardCollectionStub.calledOnce).to.equal(true); + expect(shardCollectionStub.firstCall.args).to.deep.equal([ + 'db.coll', + { + key: 1, + }, + true, + { + presplitHashedZones: true, + timeseries: { + timeField: 'ts', + }, + }, + ]); + + expect(reshardCollectionStub.calledOnce).to.equal(true); + expect(reshardCollectionStub.firstCall.args).to.deep.equal([ + 'db.coll', + { key: 1 }, + { forceRedistribution: true }, + ]); + }); + it('returns whatever shard.reshardCollection returns', async function () { const expectedResult = { ok: 1 }; sinon.stub(shard, 'reshardCollection').resolves(expectedResult); diff --git a/packages/shell-api/src/shard.ts b/packages/shell-api/src/shard.ts index 293ca6fca..bf9dda12e 100644 --- a/packages/shell-api/src/shard.ts +++ b/packages/shell-api/src/shard.ts @@ -710,16 +710,24 @@ export default class Shard extends ShellApiWithMongoClass { options, }); await this.shardCollection(ns, key, unique, options); - // SERVER-92762: Prevent unequal data distribution by setting - // numInitialChunks to 1000. - const numInitialChunks = - typeof unique === 'object' - ? unique.numInitialChunks - : options?.numInitialChunks; - return await this.reshardCollection(ns, key, { - numInitialChunks: numInitialChunks ?? 1000, + + if (typeof unique === 'object') { + options = unique; + } + + const reshardOptions: Document = { forceRedistribution: true, - }); + }; + + if (options?.numInitialChunks !== undefined) { + reshardOptions.numInitialChunks = options.numInitialChunks; + } + + if (options?.collation !== undefined) { + reshardOptions.collation = options.collation; + } + + return await this.reshardCollection(ns, key, reshardOptions); } @serverVersions(['8.0.0', ServerVersions.latest])