* An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient. * For detailed information about the connect process see the MongoClient.connect static method documentation. * * @param url - The MongoDB connection string
()
| 595 | * @see https://www.mongodb.com/docs/manual/reference/connection-string/ |
| 596 | */ |
| 597 | async connect(): Promise<this> { |
| 598 | if (this.connectionLock) { |
| 599 | return await this.connectionLock; |
| 600 | } |
| 601 | |
| 602 | try { |
| 603 | this.connectionLock = this._connect(); |
| 604 | await this.connectionLock; |
| 605 | } finally { |
| 606 | // release |
| 607 | this.connectionLock = undefined; |
| 608 | } |
| 609 | |
| 610 | return this; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Create a topology to open the connection, must be locked to avoid topology leaks in concurrency scenario. |