Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/i18n/src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,30 @@ const translations: Catalog = {
'Returns a cursor with information about metadata inconsistencies',
example: 'sh.checkMetadataConsistency(<options>)',
},
moveCollection: {
link: 'https://docs.mongodb.com/manual/reference/method/sh.moveCollection',
Copy link
Contributor Author

@mabaasit mabaasit Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current link to this helper (moveCollection) is https://www.mongodb.com/docs/upcoming/reference/method/sh.moveCollection/#mongodb-method-sh.moveCollection and the one i've added is to the future one, follows the same pattern as other existing commands here.
For the other 3 helpers, there exists no link in upcoming docs and i anyway put it here.

If this does not feel ok, I'd drop it.

description:
'Moves a single unsharded collection to a different shard.',
example: 'sh.moveCollection(ns, toShard)',
},
abortMoveCollection: {
link: 'https://docs.mongodb.com/manual/reference/method/sh.abortMoveCollection',
description:
'Abort the current moveCollection operation on a given collection',
example: 'sh.abortMoveCollection(ns)',
},
unshardCollection: {
link: 'https://docs.mongodb.com/manual/reference/method/sh.unshardCollection',
description:
'Unshard the given collection and move all data to the given shard.',
example: 'sh.unshardCollection(ns, toShard)',
},
abortUnshardCollection: {
link: 'https://docs.mongodb.com/manual/reference/method/sh.abortUnshardCollection',
description:
'Abort the current unshardCollection operation on a given collection',
example: 'sh.abortUnshardCollection(ns)',
},
},
},
},
Expand Down
114 changes: 114 additions & 0 deletions packages/shell-api/src/shard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,120 @@ describe('Shard', function () {
);
});
});

describe('moveCollection', function () {
it('calls serviceProvider.runCommandWithCheck', async function () {
await shard.moveCollection('db.coll', 'shard1');
expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
moveCollection: 'db.coll',
toShard: 'shard1',
}
);
});

it('returns whatever serviceProvider.runCommandWithCheck returns', async function () {
const expectedResult = { ok: 1 };
serviceProvider.runCommandWithCheck.resolves(expectedResult);
const result = await shard.moveCollection('db.coll', 'shard1');
expect(result).to.deep.equal(expectedResult);
});

it('throws if serviceProvider.runCommandWithCheck rejects', async function () {
const expectedError = new Error();
serviceProvider.runCommandWithCheck.rejects(expectedError);
const caughtError = await shard
.moveCollection('db.coll', 'shard1')
.catch((e) => e);
expect(caughtError).to.equal(expectedError);
});
});

describe('abortMoveCollection', function () {
it('calls serviceProvider.runCommandWithCheck', async function () {
await shard.abortMoveCollection('db.coll');
expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
abortMoveCollection: 'db.coll',
}
);
});

it('returns whatever serviceProvider.runCommandWithCheck returns', async function () {
const expectedResult = { ok: 1 };
serviceProvider.runCommandWithCheck.resolves(expectedResult);
const result = await shard.abortMoveCollection('db.coll');
expect(result).to.deep.equal(expectedResult);
});

it('throws if serviceProvider.runCommandWithCheck rejects', async function () {
const expectedError = new Error();
serviceProvider.runCommandWithCheck.rejects(expectedError);
const caughtError = await shard
.abortMoveCollection('db.coll')
.catch((e) => e);
expect(caughtError).to.equal(expectedError);
});
});

describe('unshardCollection', function () {
it('calls serviceProvider.runCommandWithCheck', async function () {
await shard.unshardCollection('db.coll', 'shard1');
expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
unshardCollection: 'db.coll',
toShard: 'shard1',
}
);
});

it('returns whatever serviceProvider.runCommandWithCheck returns', async function () {
const expectedResult = { ok: 1 };
serviceProvider.runCommandWithCheck.resolves(expectedResult);
const result = await shard.unshardCollection('db.coll', 'shard1');
expect(result).to.deep.equal(expectedResult);
});

it('throws if serviceProvider.runCommandWithCheck rejects', async function () {
const expectedError = new Error();
serviceProvider.runCommandWithCheck.rejects(expectedError);
const caughtError = await shard
.unshardCollection('db.coll', 'shard1')
.catch((e) => e);
expect(caughtError).to.equal(expectedError);
});
});

describe('abortUnshardCollection', function () {
it('calls serviceProvider.runCommandWithCheck', async function () {
await shard.abortUnshardCollection('db.coll');
expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith(
ADMIN_DB,
{
abortUnshardCollection: 'db.coll',
}
);
});

it('returns whatever serviceProvider.runCommandWithCheck returns', async function () {
const expectedResult = { ok: 1 };
serviceProvider.runCommandWithCheck.resolves(expectedResult);
const result = await shard.abortUnshardCollection('db.coll');
expect(result).to.deep.equal(expectedResult);
});

it('throws if serviceProvider.runCommandWithCheck rejects', async function () {
const expectedError = new Error();
serviceProvider.runCommandWithCheck.rejects(expectedError);
const caughtError = await shard
.abortUnshardCollection('db.coll')
.catch((e) => e);
expect(caughtError).to.equal(expectedError);
});
});
});

describe('integration', function () {
Expand Down
57 changes: 57 additions & 0 deletions packages/shell-api/src/shard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,61 @@ export default class Shard extends ShellApiWithMongoClass {
checkMetadataConsistency: 1,
});
}

@serverVersions(['8.0.0', ServerVersions.latest])
@apiVersions([])
@returnsPromise
async moveCollection(ns: string, toShard: string): Promise<Document> {
assertArgsDefinedType(
[ns, toShard],
['string', 'string'],
'Shard.moveCollection'
);
this._emitShardApiCall('moveCollection', { moveCollection: ns, toShard });
return await this._database._runAdminCommand({
moveCollection: ns,
toShard,
});
}

@serverVersions(['8.0.0', ServerVersions.latest])
@apiVersions([])
@returnsPromise
async abortMoveCollection(ns: string): Promise<Document> {
assertArgsDefinedType([ns], ['string'], 'Shard.abortMoveCollection');
this._emitShardApiCall('abortMoveCollection', { abortMoveCollection: ns });
return await this._database._runAdminCommand({ abortMoveCollection: ns });
}

@serverVersions(['8.0.0', ServerVersions.latest])
@apiVersions([])
@returnsPromise
async unshardCollection(ns: string, toShard: string): Promise<Document> {
assertArgsDefinedType(
[ns, toShard],
['string', 'string'],
'Shard.unshardCollection'
);
this._emitShardApiCall('unshardCollection', {
unshardCollection: ns,
toShard,
});
return await this._database._runAdminCommand({
unshardCollection: ns,
toShard,
});
}

@serverVersions(['8.0.0', ServerVersions.latest])
@apiVersions([])
@returnsPromise
async abortUnshardCollection(ns: string): Promise<Document> {
assertArgsDefinedType([ns], ['string'], 'Shard.abortUnshardCollection');
this._emitShardApiCall('abortUnshardCollection', {
abortUnshardCollection: ns,
});
return await this._database._runAdminCommand({
abortUnshardCollection: ns,
});
}
}