File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,43 @@ export default class ShellApi extends ShellApiClass {
263263 return mongo ;
264264 }
265265
266+ @returnType ( 'Mongo' )
267+ @platforms ( [ 'CLI' ] )
268+ public LazyMongo (
269+ uri ?: string ,
270+ fleOptions ?: ClientSideFieldLevelEncryptionOptions ,
271+ otherOptions ?: { api ?: ServerApi | ServerApiVersion }
272+ ) : Mongo {
273+ assertCLI (
274+ this . _instanceState . initialServiceProvider . platform ,
275+ 'new Mongo connections'
276+ ) ;
277+ const mongo = new Mongo ( this . _instanceState , uri , fleOptions , otherOptions ) ;
278+ const connectPromise = mongo . connect ( ) ;
279+ connectPromise . catch ( ( ) => { } ) ;
280+ this . _instanceState . mongos . push ( mongo ) ;
281+
282+ return new Proxy ( mongo , {
283+ get : ( target , prop ) => {
284+ if ( typeof ( Mongo . prototype as any ) [ prop ] === 'function' ) {
285+ return function ( ...args : any [ ] ) {
286+ return Object . assign (
287+ ( async ( ) => {
288+ await connectPromise ;
289+ return await ( target as any ) [ prop ] ( ...args ) ;
290+ } ) ( ) ,
291+ {
292+ [ Symbol . for ( '@@mongosh.syntheticPromise' ) ] : true ,
293+ }
294+ ) ;
295+ } ;
296+ } else {
297+ return ( target as any ) [ prop ] ;
298+ }
299+ } ,
300+ } ) ;
301+ }
302+
266303 @returnsPromise
267304 @returnType ( 'Database' )
268305 @platforms ( [ 'CLI' ] )
You can’t perform that action at this time.
0 commit comments