@@ -121,13 +121,39 @@ describe('e2e direct connection', () => {
121
121
shell . assertContainsOutput ( "name: 'system.version'" ) ;
122
122
} ) ;
123
123
124
+ it ( 'fails to list databases without explicit readPreference' , async ( ) => {
125
+ const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ` ] } ) ;
126
+ await shell . waitForPrompt ( ) ;
127
+ await shell . executeLine ( 'use admin' ) ;
128
+ await shell . executeLine ( 'db.getMongo().getDBs()' ) ;
129
+ shell . assertContainsError ( 'MongoServerError: not primary' ) ;
130
+ } ) ;
131
+
132
+ it ( 'lists databases when readPreference is in the connection string' , async ( ) => {
133
+ const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ?readPreference=secondaryPreferred` ] } ) ;
134
+ await shell . waitForPrompt ( ) ;
135
+ await shell . executeLine ( 'use admin' ) ;
136
+ await shell . executeLine ( 'db.getMongo().getDBs()' ) ;
137
+ shell . assertContainsOutput ( "name: 'admin'" ) ;
138
+ } ) ;
139
+
140
+ it ( 'lists databases when readPreference is set via Mongo' , async ( ) => {
141
+ const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ` ] } ) ;
142
+ await shell . waitForPrompt ( ) ;
143
+ await shell . executeLine ( 'use admin' ) ;
144
+ await shell . executeLine ( 'db.getMongo().setReadPref("secondaryPreferred")' ) ;
145
+ await shell . executeLine ( 'db.getMongo().getDBs()' ) ;
146
+ shell . assertContainsOutput ( "name: 'admin'" ) ;
147
+ } ) ;
148
+
124
149
it ( 'lists collections and dbs using show by default' , async ( ) => {
125
150
const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ` ] } ) ;
126
151
await shell . waitForPrompt ( ) ;
127
152
await shell . executeLine ( 'use admin' ) ;
128
153
expect ( await shell . executeLine ( 'show collections' ) ) . to . include ( 'system.version' ) ;
129
154
expect ( await shell . executeLine ( 'show dbs' ) ) . to . include ( 'admin' ) ;
130
155
} ) ;
156
+
131
157
it ( 'autocompletes collection names' , async function ( ) {
132
158
if ( process . arch === 's390x' ) {
133
159
return this . skip ( ) ; // https://jira.mongodb.org/browse/MONGOSH-746
0 commit comments