File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -812,22 +812,33 @@ export default class Database extends ShellApiClass {
812
812
@returnsPromise
813
813
async isMaster ( ) : Promise < Document > {
814
814
this . _emitDatabaseApiCall ( 'isMaster' , { } ) ;
815
- return await this . _runCommand (
815
+ const result = await this . _runCommand (
816
816
{
817
817
isMaster : 1 ,
818
818
}
819
819
) ;
820
+ result . isWritablePrimary = result . ismaster ;
821
+ return result ;
820
822
}
821
823
822
824
@returnsPromise
823
825
@serverVersions ( [ '5.0.0' , ServerVersions . latest ] )
824
826
async hello ( ) : Promise < Document > {
825
827
this . _emitDatabaseApiCall ( 'hello' , { } ) ;
826
- return await this . _runCommand (
827
- {
828
- hello : 1 ,
828
+ try {
829
+ return await this . _runCommand (
830
+ {
831
+ hello : 1 ,
832
+ }
833
+ ) ;
834
+ } catch ( err ) {
835
+ if ( err . codeName === 'CommandNotFound' ) {
836
+ const result = await this . isMaster ( ) ;
837
+ delete result . ismaster ;
838
+ return result ;
829
839
}
830
- ) ;
840
+ throw err ;
841
+ }
831
842
}
832
843
833
844
@returnsPromise
Original file line number Diff line number Diff line change @@ -1927,15 +1927,18 @@ describe('Shell API (integration)', function() {
1927
1927
describe ( 'database commands' , ( ) => {
1928
1928
it ( 'db.isMaster() works' , async ( ) => {
1929
1929
expect ( ( await database . isMaster ( ) ) . ismaster ) . to . equal ( true ) ;
1930
+ expect ( ( await database . isMaster ( ) ) . isWritablePrimary ) . to . equal ( true ) ;
1931
+ } ) ;
1932
+
1933
+ it ( 'db.hello() works' , async ( ) => {
1934
+ const result = await database . hello ( ) ;
1935
+ expect ( result . ismaster ) . to . equal ( undefined ) ;
1936
+ expect ( result . isWritablePrimary ) . to . equal ( true ) ;
1930
1937
} ) ;
1931
1938
1932
1939
context ( 'with 5.0+ server' , ( ) => {
1933
1940
skipIfServerVersion ( testServer , '<= 4.4' ) ;
1934
1941
1935
- it ( 'db.hello() works' , async ( ) => {
1936
- expect ( ( await database . hello ( ) ) . isWritablePrimary ) . to . equal ( true ) ;
1937
- } ) ;
1938
-
1939
1942
it ( 'db.rotateCertificates() works' , async ( ) => {
1940
1943
expect ( ( await database . rotateCertificates ( ) ) . ok ) . to . equal ( 1 ) ;
1941
1944
expect ( ( await database . rotateCertificates ( 'message' ) ) . ok ) . to . equal ( 1 ) ;
You can’t perform that action at this time.
0 commit comments