Skip to content

Commit 7d18402

Browse files
authored
feat(shell-api): add db.rotateCertificates and db.hello MONGOSH-277 (#820)
(db.hello() is part of MONGOSH-558, but I guess having it earlier than later is not a bad thing.)
1 parent 558922c commit 7d18402

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

packages/i18n/src/locales/en_US.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,16 @@ const translations: Catalog = {
11461146
description: 'Calls the isMaster command',
11471147
example: 'db.isMaster()'
11481148
},
1149+
hello: {
1150+
link: 'https://docs.mongodb.com/manual/reference/method/db.hello',
1151+
description: 'Calls the hello command',
1152+
example: 'db.hello()'
1153+
},
1154+
rotateCertificates: {
1155+
link: 'https://docs.mongodb.com/manual/reference/method/db.rotateCertificates',
1156+
description: 'Calls the rotateCertificates command',
1157+
example: 'db.rotateCertificates()'
1158+
},
11491159
serverBuildInfo: {
11501160
link: 'https://docs.mongodb.com/manual/reference/method/db.serverBuildInfo',
11511161
description: 'returns the db serverBuildInfo. uses the buildInfo command',

packages/shell-api/src/database.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,17 @@ export default class Database extends ShellApiClass {
819819
);
820820
}
821821

822+
@returnsPromise
823+
@serverVersions(['5.0.0', ServerVersions.latest])
824+
async hello(): Promise<Document> {
825+
this._emitDatabaseApiCall('hello', {});
826+
return await this._runCommand(
827+
{
828+
hello: 1,
829+
}
830+
);
831+
}
832+
822833
@returnsPromise
823834
async serverBuildInfo(): Promise<Document> {
824835
this._emitDatabaseApiCall('serverBuildInfo', {});
@@ -870,6 +881,17 @@ export default class Database extends ShellApiClass {
870881
);
871882
}
872883

884+
@returnsPromise
885+
@serverVersions(['5.0.0', ServerVersions.latest])
886+
async rotateCertificates(message?: string): Promise<Document> {
887+
this._emitDatabaseApiCall('rotateCertificates', { message });
888+
return await this._runAdminCommand(
889+
{
890+
serverStatus: 1, message
891+
}
892+
);
893+
}
894+
873895
@returnsPromise
874896
async printCollectionStats(scale = 1): Promise<Document> {
875897
if (typeof scale !== 'number' || scale < 1) {

packages/shell-api/src/integration.spec.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,11 +1922,23 @@ describe('Shell API (integration)', function() {
19221922
});
19231923
});
19241924
});
1925-
describe('Field-level encryption', () => {
1926-
// This test is temporary and can go away once we actually implement FLE
1927-
// functionality.
1928-
it('native addon is present', () => {
1929-
expect(typeof serviceProvider.fle.ClientEncryption).to.equal('function');
1925+
1926+
describe('database commands', () => {
1927+
it('db.isMaster() works', async() => {
1928+
expect((await database.isMaster()).ismaster).to.equal(true);
1929+
});
1930+
1931+
context('with 5.0+ server', () => {
1932+
skipIfServerVersion(testServer, '<= 4.4');
1933+
1934+
it('db.hello() works', async() => {
1935+
expect((await database.hello()).isWritablePrimary).to.equal(true);
1936+
});
1937+
1938+
it('db.rotateCertificates() works', async() => {
1939+
expect((await database.rotateCertificates()).ok).to.equal(1);
1940+
expect((await database.rotateCertificates('message')).ok).to.equal(1);
1941+
});
19301942
});
19311943
});
19321944

0 commit comments

Comments
 (0)