From e0165e75ee818c759b51a7fa3b0b3adc6befa347 Mon Sep 17 00:00:00 2001 From: Alexis Fournier <75622873+a-fournier@users.noreply.github.com> Date: Mon, 17 Apr 2023 18:03:00 +0200 Subject: [PATCH] fix: add directConnection options to MongoDB connection (#9955) Co-authored-by: afournier --- docs/data-source-options.md | 2 ++ docs/zh_CN/connection-options.md | 2 ++ src/driver/mongodb/MongoConnectionOptions.ts | 5 +++++ src/driver/mongodb/MongoDriver.ts | 1 + 4 files changed, 10 insertions(+) diff --git a/docs/data-source-options.md b/docs/data-source-options.md index a4de60e66..e8db9a504 100644 --- a/docs/data-source-options.md +++ b/docs/data-source-options.md @@ -506,6 +506,8 @@ Different RDBMS-es have their own specific options. - `authMechanism` - Sets the authentication mechanism that MongoDB will use to authenticate the connection. +- `directConnection` - Specifies whether to force dispatch all operations to the specified host. + ## `sql.js` data source options - `database`: The raw UInt8Array database that should be imported. diff --git a/docs/zh_CN/connection-options.md b/docs/zh_CN/connection-options.md index 8fa09c8dd..2b7e8b27b 100644 --- a/docs/zh_CN/connection-options.md +++ b/docs/zh_CN/connection-options.md @@ -375,6 +375,8 @@ - `authMechanism` - 设置MongoDB用于验证连接的身份验证机制。 +- `directConnection` - 指定是否强制将所有操作分派到指定的主机。 + > 注: 由于译者对MongoDB理解不够深入,故一些翻译直接使用了机翻,因此会有些词不达意,如有更好的翻译选项,请提交PR进行完善。 ## `sql.js` diff --git a/src/driver/mongodb/MongoConnectionOptions.ts b/src/driver/mongodb/MongoConnectionOptions.ts index 383ccc062..88199dd05 100644 --- a/src/driver/mongodb/MongoConnectionOptions.ts +++ b/src/driver/mongodb/MongoConnectionOptions.ts @@ -46,6 +46,11 @@ export interface MongoConnectionOptions extends BaseDataSourceOptions { */ readonly database?: string + /** + * Specifies whether to force dispatch all operations to the specified host. Default: false + */ + readonly directConnection?: boolean + /** * The driver object * This defaults to require("mongodb") diff --git a/src/driver/mongodb/MongoDriver.ts b/src/driver/mongodb/MongoDriver.ts index b52fe0d6d..3057e1a54 100644 --- a/src/driver/mongodb/MongoDriver.ts +++ b/src/driver/mongodb/MongoDriver.ts @@ -217,6 +217,7 @@ export class MongoDriver implements Driver { "useUnifiedTopology", "autoEncryption", "retryWrites", + "directConnection", ] cteCapabilities: CteCapabilities = {