@@ -15,6 +15,7 @@ import { Document, ServiceProvider } from '@mongosh/service-provider-core';
15
15
import { MongoshInvalidInputError } from '@mongosh/errors' ;
16
16
import AsyncWriter from '@mongosh/async-rewriter' ;
17
17
import { toIgnore } from './decorators' ;
18
+ import NoDatabase from './no-db' ;
18
19
19
20
/**
20
21
* Anything to do with the internal shell state is stored here.
@@ -30,21 +31,31 @@ export default class ShellInternalState {
30
31
public context : any ;
31
32
public mongos : Mongo [ ] ;
32
33
public shellApi : ShellApi ;
33
- constructor ( initialServiceProvider : ServiceProvider , messageBus : any = new EventEmitter ( ) ) {
34
+ public cliOptions : any ;
35
+ constructor ( initialServiceProvider : ServiceProvider , messageBus : any = new EventEmitter ( ) , cliOptions : any = { } ) {
34
36
this . initialServiceProvider = initialServiceProvider ;
35
37
this . messageBus = messageBus ;
36
38
this . asyncWriter = new AsyncWriter ( signatures ) ;
37
39
this . shellApi = new ShellApi ( this ) ;
38
- const mongo = new Mongo ( this ) ;
40
+ this . mongos = [ ] ;
41
+ this . connectionInfo = { buildInfo : { } } ;
42
+ if ( ! cliOptions . nodb ) {
43
+ const mongo = new Mongo ( this ) ;
44
+ this . mongos . push ( mongo ) ;
45
+ this . currentDb = mongo . getDB ( 'test' ) ; // TODO: set to CLI arg
46
+ } else {
47
+ this . currentDb = new NoDatabase ( ) as Database ;
48
+ }
39
49
this . currentCursor = null ;
40
- this . currentDb = mongo . getDB ( 'test' ) ; // TODO: set to CLI arg
41
50
this . context = { } ;
42
- this . mongos = [ mongo ] ;
51
+ this . cliOptions = cliOptions ;
43
52
}
44
53
45
54
async fetchConnectionInfo ( ) : Promise < void > {
46
- this . connectionInfo = await this . currentDb . mongo . serviceProvider . getConnectionInfo ( ) ;
47
- this . messageBus . emit ( 'mongosh:connect' , this . connectionInfo . extraInfo ) ;
55
+ if ( ! this . cliOptions . nodb ) {
56
+ this . connectionInfo = await this . currentDb . mongo . serviceProvider . getConnectionInfo ( ) ;
57
+ this . messageBus . emit ( 'mongosh:connect' , this . connectionInfo . extraInfo ) ;
58
+ }
48
59
}
49
60
50
61
async close ( p ) : Promise < void > {
@@ -95,6 +106,7 @@ export default class ShellInternalState {
95
106
contextObject . help = this . shellApi . help ;
96
107
contextObject . printjson = contextObject . print ;
97
108
Object . assign ( contextObject , ShellBson ) ;
109
+
98
110
contextObject . rs = new ReplicaSet ( this . currentDb . mongo ) ;
99
111
contextObject . sh = new Shard ( this . currentDb . mongo ) ;
100
112
0 commit comments