

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Amazon DocumentDB （與 MongoDB 相容） 做為 的來源 AWS DMS
<a name="CHAP_Source.DocumentDB"></a>

如需 AWS DMS 支援作為來源之 Amazon DocumentDB (with MongoDB compatibility) 版本的相關資訊，請參閱 [的來源 AWS DMS](CHAP_Introduction.Sources.md)。

 使用 Amazon DocumentDB 作為來源，您可以將資料從 Amazon DocumentDB 叢集遷移到另一個 Amazon DocumentDB 叢集。您也可以將資料從 Amazon DocumentDB 叢集遷移到 支援的其他目標端點之一 AWS DMS。

如果您剛開始使用 Amazon DocumentDB，請注意以下 Amazon DocumentDB 資料庫的重要概念：
+ Amazon DocumentDB 中的記錄是*文件*，是由欄位/值對組成的資料結構。欄位值可以包含其他文件、陣列和文件的陣列。文件約相當於關聯式資料庫資料表中的資料列。
+ Amazon DocumentDB 的*集合*是一組文件，約相當於關聯式資料庫資料表。
+ Amazon DocumentDB 中的*資料庫*是一組集合，大致相當於關聯式資料庫中的結構描述。

AWS DMS 使用 Amazon DocumentDB 做為來源、文件模式和資料表模式時， 支援兩種遷移模式。您可以在 AWS DMS 主控台中建立 Amazon DocumentDB 來源端點時，使用**中繼資料模式選項或額外連線屬性 來指定遷移模式**`nestingLevel`。您可以在以下找到說明，了解遷移模式的選擇會如何影響目標資料的結果格式。

**文件模型**  
在*文件模式*中，JSON 文件會依原狀遷移。這意味著文件資料會合併為兩個項目之一。當您使用關聯式資料庫作為目標時，資料是在目標資料表中名為 `_doc` 的單一資料欄。當您使用非關聯式資料庫作為目標時，資料是單一 JSON 文件。文件模式是預設模式，我們建議您在遷移至 Amazon DocumentDB 目標時使用此模式。  
例如，請考慮 Amazon DocumentDB 集合中名為 `myCollection` 的下列文件。  

```
 db.myCollection.find()
{ "_id" : ObjectId("5a94815f40bd44d1b02bdfe0"), "a" : 1, "b" : 2, "c" : 3 }
{ "_id" : ObjectId("5a94815f40bd44d1b02bdfe1"), "a" : 4, "b" : 5, "c" : 6 }
```
使用文件模式將資料遷移到關聯式資料庫資料表之後，資料結構如下所示。文件中的資料欄位會合併到 ` _doc` 資料欄。      
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/dms/latest/userguide/CHAP_Source.DocumentDB.html)
您可以選擇性地將額外連線屬性 `extractDocID` 設為 `true`，以建立第二個名為 `"_id"` 的資料欄，其作用如同主索引鍵。除非您使用 Amazon DocumentDB 作為目標，否則如果您要使用變更資料擷取 (CDC)，請將此參數設定為 `true`。  
搭配產生[多文件交易](https://www.mongodb.com/docs/manual/reference/method/Session.startTransaction/#mongodb-method-Session.startTransaction)的來源使用 CDC 時， `ExtractDocId` 參數**必須**設定為 `true`。如果未啟用此參數， AWS DMS 任務會在遇到多文件交易時失敗。  
如果您將新的集合新增至來源資料庫， AWS DMS 會為集合建立新的目標資料表，並複寫任何文件。

**資料表模式**  
在*資料表模式*下，AWS DMS 會將 Amazon DocumentDB 文件中每個最上層的欄位轉換成目標資料表的資料欄。如果欄位為巢狀，請將巢狀值 AWS DMS 扁平化為單一資料欄。 AWS DMS 然後將索引鍵欄位和資料類型新增至目標資料表的資料欄集。  
對於每個 Amazon DocumentDB 文件， 會將每個索引鍵和類型 AWS DMS 新增至目標資料表的資料欄集。例如，使用資料表模式， 會將先前的範例 AWS DMS 遷移至下表。      
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/dms/latest/userguide/CHAP_Source.DocumentDB.html)
巢狀值會扁平化到包含以點分隔之索引鍵名稱的資料行。資料欄命名是使用以句號分隔的扁平化欄位名稱串連。例如，將具有巢狀值 等欄位的 JSON 文件 AWS DMS 遷移`{"a" : {"b" : {"c": 1}}}`至名為 `a.b.c.`  
若要建立目標資料欄， AWS DMS 會掃描指定數量的 Amazon DocumentDB 文件，並建立一組所有欄位及其類型。 AWS DMS 然後使用此集合來建立目標資料表的資料欄。如果使用主控台建立或修改 Amazon DocumentDB 來源端點，您可以指定待掃描的文件數。預設值為 1,000 份文件。如果您使用 AWS CLI，則可以使用額外的連線屬性 `docsToInvestigate`。  
在資料表模式中， 會像這樣 AWS DMS 管理文件和集合：  
+ 當您將文件新增至現有的集合時，會複寫文件。如果欄位不存在於目標中，則不複寫這些欄位。
+ 當您更新文件時，會複寫更新的文件。如果欄位不存在於目標中，則不複寫這些欄位。
+ 完全支援刪除文件。
+ CDC 任務完成時，新增新的集合不會在目標上產生新的資料表。
+ 在變更資料擷取 (CDC) 階段中， AWS DMS 不支援重新命名集合。

**Topics**
+ [設定許可以使用 Amazon DocumentDB 作為來源](#CHAP_Source.DocumentDB.Permissions)
+ [設定 Amazon DocumentDB 叢集的 CDC](#CHAP_Source.DocumentDB.ConfigureCDC)
+ [使用 TLS 連接到 Amazon DocumentDB](#CHAP_Source.DocumentDB.TLS)
+ [建立 Amazon DocumentDB 來源端點](#CHAP_Source.DocumentDB.ConfigureEndpoint)
+ [將 Amazon DocumentDB 集合分段並平行遷移](#CHAP_Source.DocumentDB.ParallelLoad)
+ [使用 Amazon DocumentDB 做為 來源時遷移多個資料庫 AWS DMS](#CHAP_Source.DocumentDB.Multidatabase)
+ [使用 Amazon DocumentDB 做為 來源的限制 AWS DMS](#CHAP_Source.DocumentDB.Limitations)
+ [在將 Amazon DocumentDB 作為來源的情況下使用端點設定](#CHAP_Source.DocumentDB.ECAs)
+ [Amazon DocumentDB 的來源資料類型](#CHAP_Source.DocumentDB.DataTypes)

## 設定許可以使用 Amazon DocumentDB 作為來源
<a name="CHAP_Source.DocumentDB.Permissions"></a>

使用 Amazon DocumentDB 來源進行 AWS DMS 遷移時，您可以建立具有根權限的使用者帳戶。或者，您可以建立使用者，所含許可僅限於要遷移的資料庫。

以下程式碼會建立使用者作為根帳戶。

```
use admin
db.createUser(
  {
    user: "root",
    pwd: "password",
    roles: [ { role: "root", db: "admin" } ]
  })
```

若是 Amazon DocumentDB 3.6，以下程式碼會在要遷移的資料庫建立擁有最基本權限的使用者。

```
use db_name
db.createUser( 
    {
        user: "dms-user",
        pwd: "password",
        roles: [{ role: "read", db: "db_name" }]
    }
)
```

對於 Amazon DocumentDB 4.0 及更高版本， AWS DMS 會使用全部署的變更串流。在這裡，下面的程式碼會建立具有最基本權限的使用者。

```
db.createUser( 
{ 
    user: "dms-user",
    pwd: "password",
    roles: [ { role: "readAnyDatabase", db: "admin" }] 
})
```

## 設定 Amazon DocumentDB 叢集的 CDC
<a name="CHAP_Source.DocumentDB.ConfigureCDC"></a>

若要搭配 Amazon DocumentDB 使用持續複寫或 CDC， AWS DMS 需要存取 Amazon DocumentDB 叢集的變更串流。如需說明，了解叢集集合和資料庫中按時間順序排序的更新事件，請參閱《Amazon DocumentDB 開發人員指南》**中的[使用變更串流](https://docs.aws.amazon.com/documentdb/latest/developerguide/change_streams.html)。

使用 MongoDB Shell 向 Amazon DocumentDB 叢集進行驗證。然後執行下列命令以啟用變更串流。

```
db.adminCommand({modifyChangeStreams: 1,
    database: "DB_NAME",
    collection: "", 
    enable: true});
```

此方法可為資料庫中的所有集合啟用變更串流。啟用變更串流後，您可以建立遷移任務來遷移現有資料，同時複寫持續變更。即使載入大量資料， 仍會 AWS DMS 繼續擷取和套用變更。來源和目標資料庫最終將保持同步，盡可能地縮短停機時間。

**注意**  
AWS DMS 使用 操作日誌 (oplog) 來擷取進行中複寫期間的變更。如果 Amazon DocumentDB 在 AWS DMS 讀取記錄之前從 oplog 中清除記錄，您的任務將會失敗。我們建議調整 oplog 的大小，以將變更保留至少 24 小時。

## 使用 TLS 連接到 Amazon DocumentDB
<a name="CHAP_Source.DocumentDB.TLS"></a>

依預設，新建立的 Amazon DocumentDB 叢集僅接受使用 Transport Layer Security (TLS) 的安全連線。啟用 TLS 時，每個 Amazon DocumentDB 連線都需要公有金鑰。

您可以從 AWS託管的 Amazon S3 儲存貯體下載 檔案，以擷取 Amazon DocumentDB 的公有金鑰。 `rds-combined-ca-bundle.pem` Amazon S3 如需下載此檔案的相關資訊，請參閱《Amazon DocumentDB開發人員指南》**中的[使用 TLS 加密連線](https://docs.aws.amazon.com/documentdb/latest/developerguide/security.encryption.ssl.html)。

下載`rds-combined-ca-bundle.pem`檔案後，您可以匯入其中包含的公有金鑰 AWS DMS。下列步驟說明如何執行這項操作。

**使用 AWS DMS 主控台匯入您的公有金鑰**

1. 登入 AWS 管理主控台 並選擇 AWS DMS。

1. 在導覽窗格中，選擇 **Certificates (憑證)**。

1. 選擇 **Import certificate (匯入憑證)**。隨即顯示**匯入新的 CA 憑證**頁面。

1. 在**憑證組態**區段中，執行以下其中一項操作：
   + 針對**憑證識別碼**，輸入憑證的唯一名稱，例如 `docdb-cert`。
   + 選擇**選擇檔案**，瀏覽至您儲存 `rds-combined-ca-bundle.pem` 檔案的位置，然後加以選取。

1. 選擇 **Add new CA certificate (新增憑證授權機構憑證)**。

 AWS CLI 下列範例使用 AWS DMS `import-certificate`命令匯入公有金鑰`rds-combined-ca-bundle.pem`檔案。

```
aws dms import-certificate \
    --certificate-identifier docdb-cert \
    --certificate-pem file://./rds-combined-ca-bundle.pem
```

## 建立 Amazon DocumentDB 來源端點
<a name="CHAP_Source.DocumentDB.ConfigureEndpoint"></a>

您可以使用主控台或 AWS CLI建立 Amazon DocumentDB 來源端點。使用主控台執行以下程序。

**使用 AWS DMS 主控台設定 Amazon DocumentDB 來源端點**

1. 登入 AWS 管理主控台 並選擇 AWS DMS。

1. 在導覽窗格中選擇**端點**，然後選擇**建立端點**。

1. 對於**端點識別碼**，請提供可協助您輕鬆識別的名稱，例如 `docdb-source`。

1. 針對**來源引擎**，請選擇 **Amazon DocumentDB (with MongoDB compatibility)**。

1. 在**伺服器名稱**中，輸入 Amazon DocumentDB 資料庫端點所在的伺服器名稱。例如，您可以輸入 Amazon EC2 執行個體的公有 DNS 名稱，例如 `democluster.cluster-cjf6q8nxfefi.us-east-2.docdb.amazonaws.com`。

1. 針對**連接埠**，輸入 27017。

1. 對於 **SSL mode (SSL 模式)**，請選擇 **verify-full (完整驗證)**。如果您已在 Amazon DocumentDB 叢集上停用 SSL，則可以略過此步驟。

1. 對於 **CA 憑證**，請選擇 Amazon DocumentDB 憑證 (`rds-combined-ca-bundle.pem`)。如需新增此憑證的指示，請參閱[使用 TLS 連接到 Amazon DocumentDB](#CHAP_Source.DocumentDB.TLS)。

1. 針對**資料庫名稱**，輸入要遷移的資料庫名稱。

使用 CLI 執行以下程序。

**使用 設定 Amazon DocumentDB 來源端點 AWS CLI**
+ 執行下列 AWS DMS `create-endpoint`命令來設定 Amazon DocumentDB 來源端點，以您自己的值取代預留位置。

  ```
  aws dms create-endpoint \
             --endpoint-identifier a_memorable_name \
             --endpoint-type source \
             --engine-name docdb \
             --username value \
             --password value \
             --server-name servername_where_database_endpoint_resides \
             --port 27017 \
             --database-name name_of_endpoint_database
  ```

## 將 Amazon DocumentDB 集合分段並平行遷移
<a name="CHAP_Source.DocumentDB.ParallelLoad"></a>

為了改善遷移任務的效能，Amazon DocumentDB 來源端點在資料表對應中支援兩個平行完全載入功能選項。換句話說，您可以在 JSON 設定中為平行完全載入，使用自動分段或包含資料表對應的範圍分割選項，以平行遷移集合。自動分割選項可讓您指定 的條件 AWS DMS ，以自動分割來源以進行每個執行緒中的遷移。範圍分割選項可讓您告知 DMS AWS DMS 在每個執行緒中遷移的每個區段的特定範圍。如需這些設定的詳細資訊，請參閱[資料表和集合設定規則與操作](CHAP_Tasks.CustomizingTasks.TableMapping.SelectionTransformation.Tablesettings.md)。

### 使用自動分段範圍平行遷移 Amazon DocumentDB 資料庫
<a name="CHAP_Source.DocumentDB.ParallelLoad.AutoPartitioned"></a>

您可以平行遷移文件，方法是指定 條件 AWS DMS ，讓 自動分割 （分割） 每個執行緒的資料，尤其是每個執行緒要遷移的文件數量。使用此方法時， AWS DMS 嘗試最佳化區段邊界，以獲得每個執行緒的最大效能。

您可以使用下列資料表對應中的資料表設定選項來指定分段條件：


|  資料表設定選項  |  Description  | 
| --- | --- | 
|  `"type"`  |  (必要) 設為 `"partitions-auto"` 以將 Amazon DocumentDB 作為來源。  | 
|  `"number-of-partitions"`  |  (選用) 用於遷移的分割 (區段) 總數。預設為 16。  | 
|  `"collection-count-from-metadata"`  |  （選用） 如果設定為 `true`， AWS DMS 會使用預估的集合計數來判斷分割區數量。如果設定為 `false`， AWS DMS 會使用實際的收集計數。預設值為 `true`。  | 
|  `"max-records-skip-per-page"`  |  （選用） 決定每個分割區的邊界時要一次略過的記錄數目。 AWS DMS 會使用分頁略過方法來決定分割區的最小邊界。預設值為 10000。設定相對較大的值可能會導致游標逾時和任務失敗。設定相對較低的值會導致每頁操作數增加，而且完全載入速度較慢。  | 
|  `"batch-size"`  |  (選用) 限制在單一批次中傳回的文件數。每個批次都需要往返伺服器。如果批次大小為零 (0)，游標會使用伺服器定義的批次大小上限。預設值為 0。  | 

下列範例顯示自動分段的資料表對應。

```
{
    "rules": [
        {
            "rule-type": "selection",
            "rule-id": "1",
            "rule-name": "1",
            "object-locator": {
                "schema-name": "admin",
                "table-name": "departments"
            },
            "rule-action": "include",
            "filters": []
        },
        {
            "rule-type": "table-settings",
            "rule-id": "2",
            "rule-name": "2",
            "object-locator": {
                "schema-name": "admin",
                "table-name": "departments"
            },
            "parallel-load": {
                "type": "partitions-auto",
                "number-of-partitions": 5,
                "collection-count-from-metadata": "true",
                "max-records-skip-per-page": 1000000,
                "batch-size": 50000
            }
        }
    ]
}
```

自動分段具有下列限制。每個區段的遷移會分別擷取集合計數和收集下限 `_id`。然後，其會使用分頁略過來計算該區段的最小邊界。因此，請確保每個集合的最小 `_id` 值保持不變，直到集合中的所有區段邊界都經過計算為止。如果您在區段邊界計算期間變更集合的最小 `_id` 值，這可能會導致資料遺失或重複的資料列錯誤。

### 使用特定區段範圍平行遷移 Amazon DocumentDB 資料庫
<a name="CHAP_Source.DocumentDB.ParallelLoad.Ranges"></a>

下列範例顯示具有七個項目的 Amazon DocumentDB 集合，並將 `_id` 作為主索引鍵。

![\[具有七個項目的 Amazon DocumentDB 集合。\]](http://docs.aws.amazon.com/zh_tw/dms/latest/userguide/images/datarep-docdb-collection.png)


若要將集合分割成三個區段並平行遷移，您可以如下列 JSON 範例所示，將資料表對應規則新增至遷移任務。

```
{ // Task table mappings:
  "rules": [
    {
      "rule-type": "selection",
      "rule-id": "1",
      "rule-name": "1",
      "object-locator": {
        "schema-name": "testdatabase",
        "table-name": "testtable"
      },
      "rule-action": "include"
    }, // "selection" :"rule-type"
    {
      "rule-type": "table-settings",
      "rule-id": "2",
      "rule-name": "2",
      "object-locator": {
        "schema-name": "testdatabase",
        "table-name": "testtable"
      },
      "parallel-load": {
        "type": "ranges",
        "columns": [
           "_id",
           "num"
        ],
        "boundaries": [
          // First segment selects documents with _id less-than-or-equal-to 5f805c97873173399a278d79
          // and num less-than-or-equal-to 2.
          [
             "5f805c97873173399a278d79",
             "2"
          ],
          // Second segment selects documents with _id > 5f805c97873173399a278d79 and
          // _id less-than-or-equal-to 5f805cc5873173399a278d7c and
          // num > 2 and num less-than-or-equal-to 5.
          [
             "5f805cc5873173399a278d7c",
             "5"
          ]                                   
          // Third segment is implied and selects documents with _id > 5f805cc5873173399a278d7c.
        ] // :"boundaries"
      } // :"parallel-load"
    } // "table-settings" :"rule-type"
  ] // :"rules"
} // :Task table mappings
```

該資料表對應定義會將來源集合分割為三個區段，並平行遷移。以下是分段邊界。

```
Data with _id less-than-or-equal-to "5f805c97873173399a278d79" and num less-than-or-equal-to 2 (2 records)
Data with _id less-than-or-equal-to "5f805cc5873173399a278d7c" and num less-than-or-equal-to 5 and not in (_id less-than-or-equal-to  "5f805c97873173399a278d79" and num less-than-or-equal-to 2) (3 records)
Data not in (_id less-than-or-equal-to "5f805cc5873173399a278d7c" and num less-than-or-equal-to 5) (2 records)
```

遷移任務完成後，您可以如下列範例所示，從任務日誌中確認資料表是否是平行載入。您也可以驗證用來從來源資料表卸載每個區段的 Amazon DocumentDB `find` 子句。

```
[TASK_MANAGER    ] I:  Start loading segment #1 of 3 of table 'testdatabase'.'testtable' (Id = 1) by subtask 1. Start load timestamp 0005B191D638FE86  (replicationtask_util.c:752)

[SOURCE_UNLOAD   ] I:  Range Segmentation filter for Segment #0 is initialized.   (mongodb_unload.c:157)

[SOURCE_UNLOAD   ] I:  Range Segmentation filter for Segment #0 is: { "_id" : { "$lte" : { "$oid" : "5f805c97873173399a278d79" } }, "num" : { "$lte" : { "$numberInt" : "2" } } }  (mongodb_unload.c:328)

[SOURCE_UNLOAD   ] I: Unload finished for segment #1 of segmented table 'testdatabase'.'testtable' (Id = 1). 2 rows sent.

[TASK_MANAGER    ] I: Start loading segment #1 of 3 of table 'testdatabase'.'testtable' (Id = 1) by subtask 1. Start load timestamp 0005B191D638FE86 (replicationtask_util.c:752)
 
[SOURCE_UNLOAD   ] I: Range Segmentation filter for Segment #0 is initialized. (mongodb_unload.c:157) 

[SOURCE_UNLOAD   ] I: Range Segmentation filter for Segment #0 is: { "_id" : { "$lte" : { "$oid" : "5f805c97873173399a278d79" } }, "num" : { "$lte" : { "$numberInt" : "2" } } } (mongodb_unload.c:328)
 
[SOURCE_UNLOAD   ] I: Unload finished for segment #1 of segmented table 'testdatabase'.'testtable' (Id = 1). 2 rows sent.

[TARGET_LOAD     ] I: Load finished for segment #1 of segmented table 'testdatabase'.'testtable' (Id = 1). 1 rows received. 0 rows skipped. Volume transfered 480.

[TASK_MANAGER    ] I: Load finished for segment #1 of table 'testdatabase'.'testtable' (Id = 1) by subtask 1. 2 records transferred.
```

目前， AWS DMS 支援下列 Amazon DocumentDB 資料類型做為區段索引鍵資料欄：
+ Double
+ String
+ ObjectId
+ 32 位元整數
+ 64 位元整數

## 使用 Amazon DocumentDB 做為 來源時遷移多個資料庫 AWS DMS
<a name="CHAP_Source.DocumentDB.Multidatabase"></a>

AWS DMS 3.4.5 版和更高版本僅支援在 Amazon DocumentDB 4.0 版和更高版本的任務中遷移多個資料庫。若想要遷移多個資料庫，請執行以下作業：

1. 當您建立 Amazon DocumentDB 來源端點時：
   + 在 AWS 管理主控台 的 中 AWS DMS，在**建立****端點頁面上的端點組態**下將**資料庫名稱**保留空白。
   + 在 AWS Command Line Interface (AWS CLI) 中，將空字串值指派給您為 **CreateEndpoint** 動作指定的 **DocumentDBSettings** 中的 **DatabaseName** 參數。

1. 對於要從此 Amazon DocumentDB 來源端點遷移的每個資料庫，請使用主控台中的引導式輸入或直接使用 JSON，將每個資料庫的名稱指定為任務資料表對應的結構描述名稱。如需引導式輸入的相關資訊，請參閱[從主控台指定資料表選取及轉換](CHAP_Tasks.CustomizingTasks.TableMapping.Console.md)的描述。如需 JSON 的相關資訊，請參閱[選取規則與動作](CHAP_Tasks.CustomizingTasks.TableMapping.SelectionTransformation.Selections.md)。

例如，您可以在下列指定 JSON 以遷移三個 Amazon DocumentDB 資料庫。

**Example 遷移結構描述中的所有資料表**  
下列 JSON 會將來源端點中 `Customers`、`Orders` 和 `Suppliers` 資料庫中的所有資料表遷移至目標端點。  

```
{
    "rules": [
        {
            "rule-type": "selection",
            "rule-id": "1",
            "rule-name": "1",
            "object-locator": {
                "schema-name": "Customers",
                "table-name": "%"
            },
            "object-locator": {
                "schema-name": "Orders",
                "table-name": "%"
            },
            "object-locator": {
                "schema-name": "Inventory",
                "table-name": "%"
            },
            "rule-action": "include"
        }
    ]
}
```

## 使用 Amazon DocumentDB 做為 來源的限制 AWS DMS
<a name="CHAP_Source.DocumentDB.Limitations"></a>

以下是使用 Amazon DocumentDB 做為 來源時的限制 AWS DMS：
+ 當 `_id` 選項設為單獨的資料行，ID 字串不能超過 200 個字元。
+ 在資料表模式中，物件 ID 和陣列類型索引鍵都會轉換成以 `oid` 和 `array` 為前綴的資料行。

  這些資料行在內部使用加上前綴的名稱參考。如果您在 中使用參考這些欄 AWS DMS 的轉換規則，請務必指定字首欄。例如，指定 `${oid__id}` (而不是 `${_id}`) 或是 (`${array__addresses}` 而不是 `${_addresses}`)。
+  集合名稱和索引鍵名稱不能包含金錢符號 (\$1)。
+ 資料表模式和文件模式都有前文討論的限制。
+ 使用自動分段進行平行遷移時具有前述限制。
+ Amazon DocumentDB (MongoDB compatible) 來源不支援使用特定時間戳記作為變更資料擷取 (CDC) 的起始位置。進行中複寫任務會開始擷取變更 (不論時間戳記為何)。
+ AWS DMS 對於低於 3.5.2 的 AWS DMS 版本， 不支援巢狀層級大於 97 的文件。
+ DocumentDB 不支援來源篩選條件。
+ AWS DMS 不支援在彈性叢集模式中將 DocumentDB 的 CDC （變更資料擷取） 複寫做為來源。

## 在將 Amazon DocumentDB 作為來源的情況下使用端點設定
<a name="CHAP_Source.DocumentDB.ECAs"></a>

您可以使用端點設定來設定 Amazon DocumentDB 來源資料表，類似於使用額外的連線屬性。當您使用 AWS DMS 主控台或使用 中的 `create-endpoint`命令搭配 `--doc-db-settings '{"EndpointSetting": "value", ...}'` JSON 語法來建立來源端點時[AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/dms/index.html)，您可以指定設定。

下列資料表顯示您可以在將 Amazon DocumentDB 作為來源搭配使用的端點設定。


| 屬性名稱 | 有效值 | 預設值和描述 | 
| --- | --- | --- | 
|   `NestingLevel`   |  `"none"` `"one"`  |  `"none"`：指定 `"none"` 使用文件模式。指定 `"one"` 使用資料表模式。  | 
|   `ExtractDocID`   |  `true` `false`  |  `false`：將 `NestingLevel` 設為 `"none"` 時，請使用此屬性。 搭配產生[多文件交易](https://www.mongodb.com/docs/manual/reference/method/Session.startTransaction/#mongodb-method-Session.startTransaction)的來源使用 CDC 時， `ExtractDocId` 參數**必須**設定為 `true`。如果未啟用此參數， AWS DMS 任務會在遇到多文件交易時失敗。  | 
|   `DocsToInvestigate`   |  正整數會大於 `0`。  |  `1000`：將 `NestingLevel` 設為 `"one"` 時，請使用此屬性。  | 
|   `ReplicateShardCollections `   |  `true` `false`  |  當為 true 時， 會將資料 AWS DMS 複寫至碎片集合。只有在目標端點是 DocumentDB 彈性叢集時， AWS DMS 才會使用此設定。 當此設定為 true 時，請注意以下事項： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/dms/latest/userguide/CHAP_Source.DocumentDB.html)  | 

## Amazon DocumentDB 的來源資料類型
<a name="CHAP_Source.DocumentDB.DataTypes"></a>

您可以在下表中找到在使用 AWS DMS時支援的 Amazon DocumentDB 來源資料類型。您也可以在此資料表中找到來自 AWS DMS 資料類型的預設映射。如需資料類型的詳細資訊，請參閱 MongoDB 文件中的 [BSON 類型](https://docs.mongodb.com/manual/reference/bson-types)。

如需如何檢視從目標映射的資料類型資訊，請參閱您要使用的目標端點一節。

如需 AWS DMS 資料類型的詳細資訊，請參閱 [AWS Database Migration Service 的資料類型](CHAP_Reference.DataTypes.md)。


|  Amazon DocumentDB 資料類型  |  AWS DMS 資料類型  | 
| --- | --- | 
| Boolean | Bool | 
| 二進位 | BLOB | 
| Date | Date | 
| 時間戳記 | Date | 
| Int | INT4 | 
| Long | INT8 | 
| Double | REAL8 | 
| 字串 (UTF-8) | CLOB | 
| 陣列 | CLOB | 
| OID | String | 