(client: MongoClient)
| 142 | * @internal |
| 143 | */ |
| 144 | export async function autoConnect(client: MongoClient): Promise<Topology> { |
| 145 | if (client.topology == null) { |
| 146 | if (client.s.hasBeenClosed) { |
| 147 | throw new MongoNotConnectedError('Client must be connected before running operations'); |
| 148 | } |
| 149 | client.s.options.__skipPingOnConnect = true; |
| 150 | try { |
| 151 | await client.connect(); |
| 152 | if (client.topology == null) { |
| 153 | throw new MongoRuntimeError( |
| 154 | 'client.connect did not create a topology but also did not throw' |
| 155 | ); |
| 156 | } |
| 157 | return client.topology; |
| 158 | } finally { |
| 159 | delete client.s.options.__skipPingOnConnect; |
| 160 | } |
| 161 | } |
| 162 | return client.topology; |
| 163 | } |
| 164 | |
| 165 | /** @internal */ |
| 166 | type RetryOptions = { |
no test coverage detected