* Create a new Db instance sharing the current socket connections. * * @param dbName - The name of the database we want to use. If not provided, use database name from connection string. * @param options - Optional settings for Db construction
(dbName?: string, options?: DbOptions)
| 828 | * @param options - Optional settings for Db construction |
| 829 | */ |
| 830 | db(dbName?: string, options?: DbOptions): Db { |
| 831 | options = options ?? {}; |
| 832 | |
| 833 | // Default to db from connection string if not provided |
| 834 | if (!dbName) { |
| 835 | dbName = this.s.options.dbName; |
| 836 | } |
| 837 | |
| 838 | // Copy the options and add out internal override of the not shared flag |
| 839 | const finalOptions = Object.assign({}, this.options, options); |
| 840 | |
| 841 | // Return the db object |
| 842 | const db = new Db(this, dbName, finalOptions); |
| 843 | |
| 844 | // Return the database |
| 845 | return db; |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Creates a new MongoClient instance and immediately connects it to MongoDB. |
no outgoing calls