使用資料移轉工具將您的資料移轉至 Azure Cosmos DBUse Data migration tool to migrate your data to Azure Cosmos DB

本教學課程提供使用 Azure Cosmos DB 資料移轉工具的相關指示,可將資料從各種來源匯入到 Azure Cosmos 容器和資料表。This tutorial provides instructions on using the Azure Cosmos DB Data Migration tool, which can import data from various sources into Azure Cosmos containers and tables. 您可以從 JSON 檔案、CSV 檔案、SQL、MongoDB、Azure 資料表儲存體、Amazon DynamoDB 及 Azure Cosmos DB SQL API 集合匯入資料。You can import from JSON files, CSV files, SQL, MongoDB, Azure Table storage, Amazon DynamoDB, and even Azure Cosmos DB SQL API collections. 您可將該資料遷移到集合和資料表,以便搭配 Azure Cosmos DB 使用。You migrate that data to collections and tables for use with Azure Cosmos DB. 針對 SQL API 從單一分割區集合移轉到多重分割區集合時,也可以使用資料移轉工具。The Data Migration tool can also be used when migrating from a single partition collection to a multi-partition collection for the SQL API.

您要將哪個 API 用於 Azure Cosmos DB?Which API are you going to use with Azure Cosmos DB?

本教學課程涵蓋下列工作:This tutorial covers the following tasks:

  • 安裝資料移轉工具Installing the Data Migration tool
  • 從不同的資料來源匯入資料Importing data from different data sources
  • 從 Azure Cosmos DB 匯出到 JSONExporting from Azure Cosmos DB to JSON

必要條件Prerequisites

依照本文的指示進行之前,請確定您會執行下列步驟:Before following the instructions in this article, ensure that you do the following steps:

  • 安裝 Microsoft .NET Framework 4.51 或更新版本。Install Microsoft .NET Framework 4.51 or higher.

  • 增加輸送量: 資料移轉的持續時間長短取決於您為個別集合或一組集合設定的輸送量。Increase throughput: The duration of your data migration depends on the amount of throughput you set up for an individual collection or a set of collections. 針對較大資料移轉,請務必增加輸送量。Be sure to increase the throughput for larger data migrations. 完成移轉之後,再降低輸送量以節省成本。After you've completed the migration, decrease the throughput to save costs. 如需在 Azure 入口網站增加輸送量的詳細資訊,請參閱 Azure Cosmos DB 中的效能等級定價層For more information about increasing throughput in the Azure portal, see performance levels and pricing tiers in Azure Cosmos DB.

  • 建立 Azure Cosmos DB 資源: 在您開始移轉資料之前,請先從 Azure 入口網站預先建立所有集合。Create Azure Cosmos DB resources: Before you start the migrating data, pre-create all your collections from the Azure portal. 若要遷移至具有資料庫層級輸送量的 Azure Cosmos DB 帳戶,請在建立 Azure Cosmos 容器時提供分割區索引鍵。To migrate to an Azure Cosmos DB account that has database level throughput, provide a partition key when you create the Azure Cosmos containers.

概觀Overview

資料移轉工具是一個開放原始碼解決方案,可將資料從各種來源匯入到 Azure Cosmos DB,來源包括:The Data Migration tool is an open-source solution that imports data to Azure Cosmos DB from a variety of sources, including:

  • JSON 檔案JSON files
  • MongoDBMongoDB
  • SQL ServerSQL Server
  • CSV 檔案CSV files
  • Azure 資料表儲存體Azure Table storage
  • Amazon DynamoDBAmazon DynamoDB
  • hbaseHBase
  • Azure Cosmos 容器Azure Cosmos containers

雖然匯入工具包括圖形化使用者介面 (dtui.exe),您也可以從命令列 (dt.exe) 驅動此工具。While the import tool includes a graphical user interface (dtui.exe), it can also be driven from the command-line (dt.exe). 事實上,在透過 UI 設定匯入之後,有一個選項可以輸出相關聯的命令。In fact, there's an option to output the associated command after setting up an import through the UI. 您可以轉換表格式來源資料 (例如 SQL Server 或 CSV 檔案),以在匯入期間建立階層式關聯性 (子文件)。You can transform tabular source data, such as SQL Server or CSV files, to create hierarchical relationships (subdocuments) during import. 繼續閱讀以深入了解來源選項、從每個來源匯入的範例命令、目標選項,以及檢視匯入結果。Keep reading to learn more about source options, sample commands to import from each source, target options, and viewing import results.

安裝Installation

移轉工具的原始程式碼可在 GitHub 上的這個存放庫中取得。The migration tool source code is available on GitHub in this repository. 您可以在本機下載並編譯解決方案,或下載預先編譯的二進位檔,然後執行:You can download and compile the solution locally, or download a pre-compiled binary, then run either:

  • Dtui.exe:此工具的圖形化介面版本Dtui.exe: Graphical interface version of the tool
  • Dt.exe:此工具的命令列版本Dt.exe: Command-line version of the tool

選取資料來源Select data source

一旦已安裝此工具之後,就可以匯入您的資料。Once you've installed the tool, it's time to import your data. 您要匯入的資料類型為何?What kind of data do you want to import?

匯入 JSON 檔案Import JSON files

JSON 檔案來源匯入工具選項可讓您匯入一或多個單一文件 JSON 檔案或具有 JSON 文件陣列的每個 JSON 檔案。The JSON file source importer option allows you to import one or more single document JSON files or JSON files that each have an array of JSON documents. 新增具有要匯入之 JSON 檔案的資料夾時,您可以選擇是否要以遞迴方式搜尋子資料夾中的檔案。When adding folders that have JSON files to import, you have the option of recursively searching for files in subfolders.

JSON 檔案來源選項的螢幕擷取畫面 - 資料庫移轉工具

連接字串採用下列格式:The connection string is in the following format:

AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>

  • <CosmosDB Endpoint> 是端點 URI。The <CosmosDB Endpoint> is the endpoint URI. 您可以從 Azure 入口網站中取得此值。You can get this value from the Azure portal. 瀏覽至 Azure Cosmos 帳戶。Navigate to your Azure Cosmos account. 開啟 [概觀] 窗格,並複製 URI 值。Open the Overview pane and copy the URI value.
  • <AccountKey> 是「密碼」或主要金鑰The <AccountKey> is the "Password" or PRIMARY KEY. 您可以從 Azure 入口網站中取得此值。You can get this value from the Azure portal. 瀏覽至 Azure Cosmos 帳戶。Navigate to your Azure Cosmos account. 開啟 [連接字串] 或 [金鑰] 窗格,並複製 [密碼] 或 [主要金鑰] 值。Open the Connection Strings or Keys pane, and copy the "Password" or PRIMARY KEY value.
  • <CosmosDB Database> 是 CosmosDB 資料庫名稱。The <CosmosDB Database> is the CosmosDB database name.

範例: AccountEndpoint=https://myCosmosDBName.documents.azure.com:443/;AccountKey=wJmFRYna6ttQ79ATmrTMKql8vPri84QBiHTt6oinFkZRvoe7Vv81x9sn6zlVlBY10bEPMgGM982wfYXpWXWB9w==;Database=myDatabaseNameExample: AccountEndpoint=https://myCosmosDBName.documents.azure.com:443/;AccountKey=wJmFRYna6ttQ79ATmrTMKql8vPri84QBiHTt6oinFkZRvoe7Vv81x9sn6zlVlBY10bEPMgGM982wfYXpWXWB9w==;Database=myDatabaseName

注意

使用 Verify 命令,確定可以存取連接字串欄位中指定的 Cosmos DB 帳戶。Use the Verify command to ensure that the Cosmos DB account specified in the connection string field can be accessed.

以下是匯入 JSON 檔案的一些命令列範例:Here are some command-line samples to import JSON files:

#Import a single JSON file
dt.exe /s:JsonFile /s.Files:.\Sessions.json /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:Sessions /t.CollectionThroughput:2500

#Import a directory of JSON files
dt.exe /s:JsonFile /s.Files:C:\TESessions\*.json /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:Sessions /t.CollectionThroughput:2500

#Import a directory (including sub-directories) of JSON files
dt.exe /s:JsonFile /s.Files:C:\LastFMMusic\**\*.json /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:Music /t.CollectionThroughput:2500

#Import a directory (single), directory (recursive), and individual JSON files
dt.exe /s:JsonFile /s.Files:C:\Tweets\*.*;C:\LargeDocs\**\*.*;C:\TESessions\Session48172.json;C:\TESessions\Session48173.json;C:\TESessions\Session48174.json;C:\TESessions\Session48175.json;C:\TESessions\Session48177.json /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:subs /t.CollectionThroughput:2500

#Import a single JSON file and partition the data across 4 collections
dt.exe /s:JsonFile /s.Files:D:\\CompanyData\\Companies.json /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:comp[1-4] /t.PartitionKey:name /t.CollectionThroughput:2500

從 MongoDB 匯入Import from MongoDB

重要

如果您要匯入到使用 Azure Cosmos DB MongoDB API 所設定的 Cosmos 帳戶中,請遵循這些指示If you're importing to a Cosmos account configured with Azure Cosmos DB's API for MongoDB, follow these instructions.

透過 MongoDB 來源匯入工具選項,您可以從單一 MongoDB 集合匯入,使用查詢來選擇性地篩選文件,以及使用投影來修改文件結構。With the MongoDB source importer option, you can import from a single MongoDB collection, optionally filter documents using a query, and modify the document structure by using a projection.

MongoDB 來源選項的螢幕擷取畫面

連接字串會採用標準的 MongoDB 格式:The connection string is in the standard MongoDB format:

mongodb://<dbuser>:<dbpassword>@<host>:<port>/<database>

注意

若要確定可以存取連接字串欄位中指定的 MongoDB 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the MongoDB instance specified in the connection string field can be accessed.

輸入要匯出資料的集合名稱。Enter the name of the collection from which data will be imported. 您可以選擇性地為查詢 (例如 {pop: {$gt:5000}}) 或為投影 (例如 {loc:0}) 指定或提供檔案,以篩選並塑造您所匯入的資料。You may optionally specify or provide a file for a query, such as {pop: {$gt:5000}}, or a projection, such as {loc:0}, to both filter and shape the data that you're importing.

以下是從 MongoDB 匯入的一些命令列範例:Here are some command-line samples to import from MongoDB:

#Import all documents from a MongoDB collection
dt.exe /s:MongoDB /s.ConnectionString:mongodb://<dbuser>:<dbpassword>@<host>:<port>/<database> /s.Collection:zips /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:BulkZips /t.IdField:_id /t.CollectionThroughput:2500

#Import documents from a MongoDB collection which match the query and exclude the loc field
dt.exe /s:MongoDB /s.ConnectionString:mongodb://<dbuser>:<dbpassword>@<host>:<port>/<database> /s.Collection:zips /s.Query:{pop:{$gt:50000}} /s.Projection:{loc:0} /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:BulkZipsTransform /t.IdField:_id/t.CollectionThroughput:2500

匯入 MongoDB 匯出檔案Import MongoDB export files

重要

如果您要匯入具有 MongoDB 支援的 Azure Cosmos DB 帳戶中,請遵循這些指示If you're importing to an Azure Cosmos DB account with support for MongoDB, follow these instructions.

MongoDB 匯出 JSON 檔案來源匯入工具選項可讓您匯入從 mongoexport 公用程式產生的一或多個 JSON 檔案。The MongoDB export JSON file source importer option allows you to import one or more JSON files produced from the mongoexport utility.

MongoDB 匯出來源選項的螢幕擷取畫面

新增具有要匯入之 MongoDB 匯出 JSON 檔案的資料夾,您可以選擇是否要以遞迴方式搜尋子資料夾中的檔案。When adding folders that have MongoDB export JSON files for import, you have the option of recursively searching for files in subfolders.

以下是從 MongoDB 匯出 JSON 檔案匯入的命令列範例:Here is a command-line sample to import from MongoDB export JSON files:

dt.exe /s:MongoDBExport /s.Files:D:\mongoemployees.json /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:employees /t.IdField:_id /t.Dates:Epoch /t.CollectionThroughput:2500

從 SQL Server 匯入Import from SQL Server

SQL 來源匯入工具選項可讓您從個別的 SQL Server 資料庫匯入,並使用查詢來選擇性地篩選要匯入的記錄。The SQL source importer option allows you to import from an individual SQL Server database and optionally filter the records to be imported using a query. 此外,您可以藉由指定巢狀分隔符號 (稍後將有更詳細的說明) 來修改文件結構。In addition, you can modify the document structure by specifying a nesting separator (more on that in a moment).

SQL 來源選項的螢幕擷取畫面 - 資料庫移轉工具

連接字串的格式會採用標準的 SQL 連接字串格式。The format of the connection string is the standard SQL connection string format.

注意

若要確定可以存取連接字串欄位中指定的 SQL Server 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the SQL Server instance specified in the connection string field can be accessed.

巢狀分隔符號屬性可用來在匯入期間建立階層式關聯性 (子文件)。The nesting separator property is used to create hierarchical relationships (sub-documents) during import. 請考慮下列 SQL 查詢:Consider the following SQL query:

select CAST(BusinessEntityID AS varchar) as Id, Name, AddressType as [Address.AddressType], AddressLine1 as [Address.AddressLine1], City as [Address.Location.City], StateProvinceName as [Address.Location.StateProvinceName], PostalCode as [Address.PostalCode], CountryRegionName as [Address.CountryRegionName] from Sales.vStoreWithAddresses WHERE AddressType='Main Office'

它會傳回下列 (部分) 結果:Which returns the following (partial) results:

SQL 查詢結果的螢幕擷取畫面

注意別名,例如 Address.AddressType 和 Address.Location.StateProvinceName。Note the aliases such as Address.AddressType and Address.Location.StateProvinceName. 藉由指定巢狀分隔符號 '.',匯入工具會在匯入期間建立 Address 和 Address.Location 子文件。By specifying a nesting separator of '.', the import tool creates Address and Address.Location subdocuments during the import. 在 Azure Cosmos DB 中產生的文件範例如下:Here is an example of a resulting document in Azure Cosmos DB:

{ "id":"956", "Name":"Finer Sales and Service", "Address": { "AddressType":"Main Office", "AddressLine1": "#500-75 O'Connor Street", "Location": { "City":"Ottawa", "StateProvinceName":"Ontario" }, "PostalCode":"K4B 1S2", "CountryRegionName":"Canada" } }{ "id": "956", "Name": "Finer Sales and Service", "Address": { "AddressType": "Main Office", "AddressLine1": "#500-75 O'Connor Street", "Location": { "City": "Ottawa", "StateProvinceName": "Ontario" }, "PostalCode": "K4B 1S2", "CountryRegionName": "Canada" } }

以下是從 SQL Server 匯入的一些命令列範例:Here are some command-line samples to import from SQL Server:

#Import records from SQL which match a query
dt.exe /s:SQL /s.ConnectionString:"Data Source=<server>;Initial Catalog=AdventureWorks;User Id=advworks;Password=<password>;" /s.Query:"select CAST(BusinessEntityID AS varchar) as Id, * from Sales.vStoreWithAddresses WHERE AddressType='Main Office'" /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:Stores /t.IdField:Id /t.CollectionThroughput:2500

#Import records from sql which match a query and create hierarchical relationships
dt.exe /s:SQL /s.ConnectionString:"Data Source=<server>;Initial Catalog=AdventureWorks;User Id=advworks;Password=<password>;" /s.Query:"select CAST(BusinessEntityID AS varchar) as Id, Name, AddressType as [Address.AddressType], AddressLine1 as [Address.AddressLine1], City as [Address.Location.City], StateProvinceName as [Address.Location.StateProvinceName], PostalCode as [Address.PostalCode], CountryRegionName as [Address.CountryRegionName] from Sales.vStoreWithAddresses WHERE AddressType='Main Office'" /s.NestingSeparator:. /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:StoresSub /t.IdField:Id /t.CollectionThroughput:2500

匯入 CSV 檔案並將 CSV 轉換成 JSONImport CSV files and convert CSV to JSON

CSV 檔案來源匯入工具選項可讓您匯入一或多個 CSV 檔案。The CSV file source importer option enables you to import one or more CSV files. 新增具有要匯入之 CSV 檔案的資料夾時,您可以選擇是否要以遞迴方式搜尋子資料夾中的檔案。When adding folders that have CSV files for import, you have the option of recursively searching for files in subfolders.

CSV 來源選項的螢幕擷取畫面 - CSV 轉換成 JSON

與 SQL 來源類似,巢狀分隔符號屬性可用來在匯入期間建立階層式關聯性 (子文件)。Similar to the SQL source, the nesting separator property may be used to create hierarchical relationships (sub-documents) during import. 請考慮下列 CSV 標頭資料列和資料資料列:Consider the following CSV header row and data rows:

CSV 範例記錄的螢幕擷取畫面 - CSV 轉換成 JSON

注意別名,例如 DomainInfo.Domain_Name 和 RedirectInfo.Redirecting。Note the aliases such as DomainInfo.Domain_Name and RedirectInfo.Redirecting. 藉由指定巢狀分隔符號 '.',匯入工具將會在匯入期間建立 DomainInfo 和 RedirectInfo 子文件。By specifying a nesting separator of '.', the import tool will create DomainInfo and RedirectInfo subdocuments during the import. 在 Azure Cosmos DB 中產生的文件範例如下:Here is an example of a resulting document in Azure Cosmos DB:

{ "DomainInfo": { "Domain_Name":"ACUS.GOV", "Domain_Name_Address": "https://www.ACUS.GOV" }, "Federal Agency":"Administrative Conference of the United States", "RedirectInfo": { "Redirecting":"0", "Redirect_Destination": "" }, "id":"9cc565c5-ebcd-1c03-ebd3-cc3e2ecd814d" }{ "DomainInfo": { "Domain_Name": "ACUS.GOV", "Domain_Name_Address": "https://www.ACUS.GOV" }, "Federal Agency": "Administrative Conference of the United States", "RedirectInfo": { "Redirecting": "0", "Redirect_Destination": "" }, "id": "9cc565c5-ebcd-1c03-ebd3-cc3e2ecd814d" }

匯入工具會嘗試推斷 CSV 檔案中不具引號之值的類型資訊 (加上引號的值永遠會被視為字串)。The import tool tries to infer type information for unquoted values in CSV files (quoted values are always treated as strings). 系統會依照下列順序識別類型:數字、日期時間、布林值。Types are identified in the following order: number, datetime, boolean.

下面提供兩個其他有關 CSV 匯入的注意事項:There are two other things to note about CSV import:

  1. 根據預設,不具引號的值一律會針對定位點和空格進行修剪,而具有引號的值則會以原樣方式加以保留。By default, unquoted values are always trimmed for tabs and spaces, while quoted values are preserved as-is. 您可以使用 [修剪具有引號的值] 核取方塊或 /s.TrimQuoted 命令列選項,來覆寫這個行為。This behavior can be overridden with the Trim quoted values checkbox or the /s.TrimQuoted command-line option.
  2. 根據預設,不具引號的 Null 會被視為 Null 值。By default, an unquoted null is treated as a null value. 您可以使用 [將不具引號的 NULL 視為字串] 核取方塊或 /s.NoUnquotedNulls 命令列選項,來覆寫這個行為 (亦即將不具引號的 Null 視為 "null" 字串)。This behavior can be overridden (that is, treat an unquoted null as a "null" string) with the Treat unquoted NULL as string checkbox or the /s.NoUnquotedNulls command-line option.

以下是 CSV 匯入的命令列範例:Here is a command-line sample for CSV import:

dt.exe /s:CsvFile /s.Files:.\Employees.csv /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:Employees /t.IdField:EntityID /t.CollectionThroughput:2500

從 Azure 資料表儲存體匯入Import from Azure Table storage

Azure 資料表儲存體來源匯入工具選項可讓您從個別的 Azure 資料表儲存體資料表匯入。The Azure Table storage source importer option allows you to import from an individual Azure Table storage table. 您可以選擇性地篩選要匯入的資料表實體。Optionally, you can filter the table entities to be imported.

您可以將從 Azure 資料表儲存體匯入的資料,輸出到 Azure Cosmos DB 資料表和實體以用於資料表 API。You may output data that was imported from Azure Table Storage to Azure Cosmos DB tables and entities for use with the Table API. 也可以將匯入的資料輸出到集合和文件以用於 SQL API。Imported data can also be output to collections and documents for use with the SQL API. 不過,資料表 API 只能作為命令列公用程式中的目標。However, Table API is only available as a target in the command-line utility. 您無法使用資料移轉工具使用者介面來匯出到資料表 API。You can't export to Table API by using the Data Migration tool user interface. 如需詳細資訊,請參閱匯入資料以用於 Azure Cosmos DB 資料表 APIFor more information, see Import data for use with the Azure Cosmos DB Table API.

Azure 資料表儲存體來源選項的螢幕擷取畫面

Azure 資料表儲存體連接字串的格式如下:The format of the Azure Table storage connection string is:

DefaultEndpointsProtocol=<protocol>;AccountName=<Account Name>;AccountKey=<Account Key>;

注意

若要確定可以存取連接字串欄位中指定的 Azure 資料表儲存體執行個體,請使用 Verify 命令。Use the Verify command to ensure that the Azure Table storage instance specified in the connection string field can be accessed.

輸入要從中匯入資料的 Azure 資料表名稱。Enter the name of the Azure table from to import from. 您可以選擇性地指定 篩選器You may optionally specify a filter.

Azure 資料表儲存體來源匯入工具選項具有下列其他選項:The Azure Table storage source importer option has the following additional options:

  1. 包含內部欄位Include Internal Fields
    1. 全部 - 包括所有內部欄位 (PartitionKey、RowKey 和 Timestamp)All - Include all internal fields (PartitionKey, RowKey, and Timestamp)
    2. 無 - 排除所有內部欄位None - Exclude all internal fields
    3. RowKey - 僅包含 RowKey 欄位RowKey - Only include the RowKey field
  2. 選取資料行Select Columns
    1. Azure 資料表儲存體篩選器不支援投影。Azure Table storage filters don't support projections. 如果您只想匯入特定的 Azure 資料表實體屬性,請將它們加入 [選取資料行] 清單。If you want to only import specific Azure Table entity properties, add them to the Select Columns list. 其他所有實體屬性都會被忽略。All other entity properties are ignored.

以下是從 Azure 資料表儲存體匯入的命令列範例:Here is a command-line sample to import from Azure Table storage:

dt.exe /s:AzureTable /s.ConnectionString:"DefaultEndpointsProtocol=https;AccountName=<Account Name>;AccountKey=<Account Key>" /s.Table:metrics /s.InternalFields:All /s.Filter:"PartitionKey eq 'Partition1' and RowKey gt '00001'" /s.Projection:ObjectCount;ObjectSize  /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:metrics /t.CollectionThroughput:2500

從 Amazon DynamoDB 匯入Import from Amazon DynamoDB

Amazon DynamoDB 來源匯入工具選項可讓您從單一 Amazon DynamoDB 資料表匯入。The Amazon DynamoDB source importer option allows you to import from a single Amazon DynamoDB table. 還可選擇性地篩選要匯入的實體。It can optionally filter the entities to be imported. 會提供數個範本,讓設定匯入盡量簡化。Several templates are provided so that setting up an import is as easy as possible.

Amazon DynamoDB 來源選項的螢幕擷取畫面 - 資料庫移轉工具

Amazon DynamoDB 來源選項的螢幕擷取畫面 - 資料庫移轉工具

Amazon DynamoDB 連接字串的格式如下:The format of the Amazon DynamoDB connection string is:

ServiceURL=<Service Address>;AccessKey=<Access Key>;SecretKey=<Secret Key>;

注意

若要確定可以存取連接字串欄位中指定的 Amazon DynamoDB 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the Amazon DynamoDB instance specified in the connection string field can be accessed.

以下是從 Amazon DynamoDB 匯入的命令列範例:Here is a command-line sample to import from Amazon DynamoDB:

dt.exe /s:DynamoDB /s.ConnectionString:ServiceURL=https://dynamodb.us-east-1.amazonaws.com;AccessKey=<accessKey>;SecretKey=<secretKey> /s.Request:"{   """TableName""": """ProductCatalog""" }" /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<Azure Cosmos DB Endpoint>;AccountKey=<Azure Cosmos DB Key>;Database=<Azure Cosmos database>;" /t.Collection:catalogCollection /t.CollectionThroughput:2500

從 Azure Blob 儲存體匯入Import from Azure Blob storage

JSON 檔案、MongoDB 匯出檔案和 CSV 檔案來源匯入工具選項可讓您從 Azure Blob 儲存體匯入一或多個檔案。The JSON file, MongoDB export file, and CSV file source importer options allow you to import one or more files from Azure Blob storage. 在指定 Blob 容器 URL 和帳戶金鑰之後,請提供規則運算式來選取要匯入的檔案。After specifying a Blob container URL and Account Key, provide a regular expression to select the file(s) to import.

Blob 檔案來源選項的螢幕擷取畫面

以下是從 Azure Blob 儲存體匯入 JSON 檔案的命令列範例:Here is command-line sample to import JSON files from Azure Blob storage:

dt.exe /s:JsonFile /s.Files:"blobs://<account key>@account.blob.core.windows.net:443/importcontainer/.*" /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:doctest

從 SQL API 集合匯入Import from a SQL API collection

Azure Cosmos DB 來源匯入工具選項可讓您從一或多個 Azure Cosmos 容器匯入資料,並選擇性地使用查詢來篩選文件。The Azure Cosmos DB source importer option allows you to import data from one or more Azure Cosmos containers and optionally filter documents using a query.

Azure Cosmos DB 來源選項的螢幕擷取畫面

Azure Cosmos DB 連接字串的格式如下:The format of the Azure Cosmos DB connection string is:

AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;

就像如何管理 Azure Cosmos DB 帳戶中所述,您可以從 Azure 入口網站的 [金鑰] 頁面擷取 Azure Cosmos DB 帳戶的連接字串。You can retrieve the Azure Cosmos DB account connection string from the Keys page of the Azure portal, as described in How to manage an Azure Cosmos DB account. 不過,必須以下列格式將資料庫的名稱附加至連接字串:However, the name of the database needs to be appended to the connection string in the following format:

Database=<CosmosDB Database>;

注意

若要確定可以存取連接字串欄位中指定的 Azure Cosmos DB 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the Azure Cosmos DB instance specified in the connection string field can be accessed.

若要從單一 Azure Cosmos 容器匯入,請輸入要從中匯入資料的來源集合名稱。To import from a single Azure Cosmos container, enter the name of the collection to import data from. 若要從多個 Azure Cosmos 容器匯入,可提供規則運算式來比對一或多個集合名稱 (例如 collection01 | collection02 | collection03)。To import from more than one Azure Cosmos container, provide a regular expression to match one or more collection names (for example, collection01 | collection02 | collection03). 您可以選擇性地為查詢指定或提供檔案,以篩選並塑造您所匯入的資料。You may optionally specify, or provide a file for, a query to both filter and shape the data that you're importing.

注意

因為集合欄位接受規則運算式,所以,若您要從其名稱有規則運算式字元的單一集合進行匯入,則必須對應地將那些字元逸出。Since the collection field accepts regular expressions, if you're importing from a single collection whose name has regular expression characters, then those characters must be escaped accordingly.

Azure Cosmos DB 來源匯入工具選項具有下列進階選項:The Azure Cosmos DB source importer option has the following advanced options:

  1. Include Internal Fields (包含內部欄位):指定在匯出時是否要包含 Azure Cosmos DB 文件系統屬性 (例如 _rid、_ts)。Include Internal Fields: Specifies whether or not to include Azure Cosmos DB document system properties in the export (for example, _rid, _ts).
  2. Number of Retries on Failure (失敗時的重試次數):指定與 Azure Cosmos DB 的連線發生暫時性失敗 (例如網路連線中斷) 時的重試次數。Number of Retries on Failure: Specifies the number of times to retry the connection to Azure Cosmos DB in case of transient failures (for example, network connectivity interruption).
  3. Retry Interval (重試間隔):指定與 Azure Cosmos DB 的連線發生暫時性失敗 (例如網路連線中斷) 時要等候的重試間隔時間。Retry Interval: Specifies how long to wait between retrying the connection to Azure Cosmos DB in case of transient failures (for example, network connectivity interruption).
  4. Connection Mode (連線模式):指定要與 Azure Cosmos DB 搭配使用的連線模式。Connection Mode: Specifies the connection mode to use with Azure Cosmos DB. 可用的選項包括:DirectTcp、DirectHttps 和閘道器。The available choices are DirectTcp, DirectHttps, and Gateway. 直接連線模式會比較快,但閘道器模式比較支援防火牆,因為它只會使用連接埠 443。The direct connection modes are faster, while the gateway mode is more firewall friendly as it only uses port 443.

Azure Cosmos DB 來源進階選項的螢幕擷取畫面

提示

匯入工具會預設 DirectTcp 連線模式。The import tool defaults to connection mode DirectTcp. 如果您遇到防火牆問題,請切換到閘道器連線模式,因為它只需要連接埠 443。If you experience firewall issues, switch to connection mode Gateway, as it only requires port 443.

以下是從 Azure Cosmos DB 匯入的一些命令列範例:Here are some command-line samples to import from Azure Cosmos DB:

#Migrate data from one Azure Cosmos container to another Azure Cosmos containers
dt.exe /s:DocumentDB /s.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /s.Collection:TEColl /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:TESessions /t.CollectionThroughput:2500

#Migrate data from more than one Azure Cosmos container to a single Azure Cosmos container
dt.exe /s:DocumentDB /s.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /s.Collection:comp1|comp2|comp3|comp4 /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:singleCollection /t.CollectionThroughput:2500

#Export an Azure Cosmos container to a JSON file
dt.exe /s:DocumentDB /s.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /s.Collection:StoresSub /t:JsonFile /t.File:StoresExport.json /t.Overwrite /t.CollectionThroughput:2500

提示

Azure Cosmos DB 資料匯入工具也支援從 Azure Cosmos DB 模擬器匯入資料。The Azure Cosmos DB Data Import Tool also supports import of data from the Azure Cosmos DB Emulator. 從本機模擬器匯入資料時,請將端點設定為 https://localhost:<port>When importing data from a local emulator, set the endpoint to https://localhost:<port>.

從 HBase 匯入Import from HBase

HBase 來源匯入工具選項可讓您從 HBase 資料表匯入資料,並選擇性地篩選資料。The HBase source importer option allows you to import data from an HBase table and optionally filter the data. 會提供數個範本,讓設定匯入盡量簡化。Several templates are provided so that setting up an import is as easy as possible.

HBase 檔案來源選項的螢幕擷取畫面

HBase 檔案來源選項的螢幕擷取畫面

HBase Stargate 連接字串的格式如下:The format of the HBase Stargate connection string is:

ServiceURL=<server-address>;Username=<username>;Password=<password>

注意

若要確定可以存取連接字串欄位中指定的 HBase 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the HBase instance specified in the connection string field can be accessed.

以下是從 HBase 匯入的命令列範例:Here is a command-line sample to import from HBase:

dt.exe /s:HBase /s.ConnectionString:ServiceURL=<server-address>;Username=<username>;Password=<password> /s.Table:Contacts /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;" /t.Collection:hbaseimport

匯入 SQL API (大量匯入)Import to the SQL API (Bulk Import)

為了提高效率,Azure Cosmos DB 大量匯入工具可讓您使用 Azure Cosmos DB 預存程序,從任何可用的來源選項匯入。The Azure Cosmos DB Bulk importer allows you to import from any of the available source options, using an Azure Cosmos DB stored procedure for efficiency. 此工具支援匯入到一個單一分割的 Azure Cosmos 容器。The tool supports import to one single-partitioned Azure Cosmos container. 也支援跨多個單一分割 Azure Cosmos 容器分割資料的分區化匯入。It also supports sharded import whereby data is partitioned across more than one single-partitioned Azure Cosmos container. 如需分割資料的詳細資訊,請參閱 Azure Cosmos DB 的資料分割與調整規模For more information about partitioning data, see Partitioning and scaling in Azure Cosmos DB. 此工具會建立並執行預存程序,然後從目標集合中將它刪除。The tool creates, executes, and then deletes the stored procedure from the target collection(s).

Azure Cosmos DB 大量選項的螢幕擷取畫面

Azure Cosmos DB 連接字串的格式如下:The format of the Azure Cosmos DB connection string is:

AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;

就像如何管理 Azure Cosmos DB 帳戶中所述,可從 Azure 入口網站的 [金鑰] 頁面中擷取 Azure Cosmos DB 帳戶的連接字串,但必須以下列格式將資料庫的名稱附加至連接字串:The Azure Cosmos DB account connection string can be retrieved from the Keys page of the Azure portal, as described in How to manage an Azure Cosmos DB account, however the name of the database needs to be appended to the connection string in the following format:

Database=<CosmosDB Database>;

注意

若要確定可以存取連接字串欄位中指定的 Azure Cosmos DB 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the Azure Cosmos DB instance specified in the connection string field can be accessed.

若要匯入到單一集合,請輸入要匯入資料的目標集合名稱,然後按一下 [新增] 按鈕。To import to a single collection, enter the name of the collection to import data from and click the Add button. 若要匯入到多個集合,請分別輸入每個集合的名稱,或使用下列語法來指定多個集合:collection_prefix [開始索引 - 結束索引]。To import to more than one collection, either enter each collection name individually or use the following syntax to specify more than one collection: collection_prefix[start index - end index]. 使用上述語法指定多個集合時,請記住下列指導方針:When specifying more than one collection using the aforementioned syntax, keep the following guidelines in mind:

  1. 僅支援整數範圍的名稱模式。Only integer range name patterns are supported. 例如,指定 collection[0-3] 會建立下列集合:collection0、collection1、collection2、collection3。For example, specifying collection[0-3] creates the following collections: collection0, collection1, collection2, collection3.
  2. 您可以使用縮寫的語法:collection[3] 會建立一組與步驟 1 中所述相同的集合。You can use an abbreviated syntax: collection[3] creates the same set of collections mentioned in step 1.
  3. 您可以提供一個以上的替代項目。More than one substitution can be provided. 例如,collection[0-1] [0-9] 會產生 20 個開頭為零的集合名稱 (collection01、..02、..03)。For example, collection[0-1] [0-9] generates 20 collection names with leading zeros (collection01, ..02, ..03).

指定集合名稱之後,請選擇所需的集合輸送量 (400 RU 到 10,000 RU)。Once the collection name(s) have been specified, choose the desired throughput of the collection(s) (400 RUs to 10,000 RUs). 為了達到最佳的匯入效能,請選擇較高的輸送量。For best import performance, choose a higher throughput. 如需效能層級的詳細資訊,請參閱 Azure Cosmos DB 中的效能層級For more information about performance levels, see Performance levels in Azure Cosmos DB.

注意

效能輸送量設定僅適用於建立集合。The performance throughput setting only applies to collection creation. 如果指定的集合已經存在,將不會修改其輸送量。If the specified collection already exists, its throughput won't be modified.

匯入到多個集合時,匯入工具支援以雜湊為基礎的分區化。When you import to more than one collection, the import tool supports hash-based sharding. 在此案例中,指定您想要用來做為資料分割索引鍵的文件屬性。In this scenario, specify the document property you wish to use as the Partition Key. (如果資料分割索引鍵是空白的,文件就會跨目標集合隨機進行分區化。)(If Partition Key is left blank, documents are sharded randomly across the target collections.)

您可以選擇性地指定在匯入期間,匯入來源中的哪些欄位應該作為 Azure Cosmos DB 文件識別碼屬性使用。You may optionally specify which field in the import source should be used as the Azure Cosmos DB document ID property during the import. 如果文件不包含這個屬性,則匯入工具會產生 GUID 做為識別碼屬性值。If documents don't have this property, then the import tool generates a GUID as the ID property value.

匯入期間有數個可用的進階選項。There are a number of advanced options available during import. 首先,雖然此工具包含預設的大量匯入預存程序 (BulkInsert.js),但您可以選擇指定自己的匯入預存程序:First, while the tool includes a default bulk import stored procedure (BulkInsert.js), you may choose to specify your own import stored procedure:

Azure Cosmos DB 大量插入 sproc 選項的螢幕擷取畫面

此外,匯入日期類型時 (例如從 SQL Server 或 MongoDB),有三種匯入選項可供選擇:Additionally, when importing date types (for example, from SQL Server or MongoDB), you can choose between three import options:

Azure Cosmos DB 日期時間匯入選項的螢幕擷取畫面

  • String (字串):保存為字串值String: Persist as a string value
  • Epoch:保存為 Epoch 數值Epoch: Persist as an Epoch number value
  • Both (兩者):同時保存字串和 Epoch 數值。Both: Persist both string and Epoch number values. 這個選項會建立子文件,例如:"date_joined": { "Value":"2013-10-21T21:17:25.2410000Z", "Epoch":1382390245 }This option creates a subdocument, for example: "date_joined": { "Value": "2013-10-21T21:17:25.2410000Z", "Epoch": 1382390245 }

Azure Cosmos DB 大量匯入工具含有下列其他進階選項:The Azure Cosmos DB Bulk importer has the following additional advanced options:

  1. Batch Size (批次大小):此工具的批次大小預設為 50。Batch Size: The tool defaults to a batch size of 50. 如果要匯入很大的文件,請考慮降低批次大小。If the documents to be imported are large, consider lowering the batch size. 相反地,如果要匯入很小的文件,請考慮提高批次大小。Conversely, if the documents to be imported are small, consider raising the batch size.
  2. Max Script Size (bytes) (指令碼大小上限 (位元組)):此工具的指令碼大小上限預設為 512 KB。Max Script Size (bytes): The tool defaults to a max script size of 512 KB.
  3. Disable Automatic Id Generation (停用自動識別碼產生):如果要匯入的每個文件都有識別碼欄位,則選取此選項可以提升效能。Disable Automatic Id Generation: If every document to be imported has an ID field, then selecting this option can increase performance. 遺漏唯一識別碼欄位的文件不會被匯入。Documents missing a unique ID field aren't imported.
  4. Update Existing Documents (更新現有的文件):此工具預設在發生識別碼衝突時不會取代現有的文件。Update Existing Documents: The tool defaults to not replacing existing documents with ID conflicts. 選取此選項會允許在識別碼相符時覆寫現有的文件。Selecting this option allows overwriting existing documents with matching IDs. 對於會更新現有文件的已排定資料移轉來說,這項功能相當有用。This feature is useful for scheduled data migrations that update existing documents.
  5. Number of Retries on Failure (失敗時的重試次數):指定與 Azure Cosmos DB 的連線發生暫時性失敗 (例如網路連線中斷) 時的重試頻率。Number of Retries on Failure: Specifies how often to retry the connection to Azure Cosmos DB during transient failures (for example, network connectivity interruption).
  6. Retry Interval (重試間隔):指定與 Azure Cosmos DB 的連線發生暫時性失敗 (例如網路連線中斷) 時要等候的重試間隔時間。Retry Interval: Specifies how long to wait between retrying the connection to Azure Cosmos DB in case of transient failures (for example, network connectivity interruption).
  7. Connection Mode (連線模式):指定要與 Azure Cosmos DB 搭配使用的連線模式。Connection Mode: Specifies the connection mode to use with Azure Cosmos DB. 可用的選項包括:DirectTcp、DirectHttps 和閘道器。The available choices are DirectTcp, DirectHttps, and Gateway. 直接連線模式會比較快,但閘道器模式比較支援防火牆,因為它只會使用連接埠 443。The direct connection modes are faster, while the gateway mode is more firewall friendly as it only uses port 443.

Azure Cosmos DB 大量匯入進階選項的螢幕擷取畫面

提示

匯入工具會預設 DirectTcp 連線模式。The import tool defaults to connection mode DirectTcp. 如果您遇到防火牆問題,請切換到閘道器連線模式,因為它只需要連接埠 443。If you experience firewall issues, switch to connection mode Gateway, as it only requires port 443.

匯入 SQL API (循序記錄匯入)Import to the SQL API (Sequential Record Import)

Azure Cosmos DB 循序記錄匯入工具可讓您從可用的來源選項逐筆匯入記錄。The Azure Cosmos DB sequential record importer allows you to import from an available source option on a record-by-record basis. 如果您打算匯入至已達到預存程序配額的現有集合,您可以選擇此選項。You might choose this option if you’re importing to an existing collection that has reached its quota of stored procedures. 此工具支援匯入到單一 (單一分割區和多個分割區) Azure Cosmos 容器。The tool supports import to a single (both single-partition and multi-partition) Azure Cosmos container. 也支援跨多個單一分割區或多重分割區 Azure Cosmos 容器分割資料的分區化匯入。It also supports sharded import whereby data is partitioned across more than one single-partition or multi-partition Azure Cosmos container. 如需分割資料的詳細資訊,請參閱 Azure Cosmos DB 的資料分割與調整規模For more information about partitioning data, see Partitioning and scaling in Azure Cosmos DB.

Azure Cosmos DB 循序記錄匯入選項的螢幕擷取畫面

Azure Cosmos DB 連接字串的格式如下:The format of the Azure Cosmos DB connection string is:

AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB Database>;

就像如何管理 Azure Cosmos DB 帳戶中所述,您可以從 Azure 入口網站的 [金鑰] 頁面擷取 Azure Cosmos DB 帳戶的連接字串。You can retrieve the connection string for the Azure Cosmos DB account from the Keys page of the Azure portal, as described in How to manage an Azure Cosmos DB account. 不過,必須以下列格式將資料庫的名稱附加至連接字串:However, the name of the database needs to be appended to the connection string in the following format:

Database=<Azure Cosmos database>;

注意

若要確定可以存取連接字串欄位中指定的 Azure Cosmos DB 執行個體,請使用 Verify 命令。Use the Verify command to ensure that the Azure Cosmos DB instance specified in the connection string field can be accessed.

若要匯入到單一集合,請輸入要匯入資料的目標集合名稱,然後按一下 [新增] 按鈕。To import to a single collection, enter the name of the collection to import data into, and then click the Add button. 若要匯入到多個集合,請個別地輸入每個集合名稱。To import to more than one collection, enter each collection name individually. 您也可以使用下列語法來指定多個集合:collection_prefix [開始索引 - 結束索引]。You may also use the following syntax to specify more than one collection: collection_prefix[start index - end index]. 透過上述語法指定多個集合時,請記住下列指導方針:When specifying more than one collection via the aforementioned syntax, keep the following guidelines in mind:

  1. 僅支援整數範圍的名稱模式。Only integer range name patterns are supported. 例如,指定 collection[0-3] 會建立下列集合:collection0、collection1、collection2、collection3。For example, specifying collection[0-3] creates the following collections: collection0, collection1, collection2, collection3.
  2. 您可以使用縮寫的語法:collection[3] 會建立一組與步驟 1 中所述相同的集合。You can use an abbreviated syntax: collection[3] creates the same set of collections mentioned in step 1.
  3. 您可以提供一個以上的替代項目。More than one substitution can be provided. 例如,collection[0-1] [0-9] 會建立 20 個開頭為零的集合名稱 (collection01、..02、..03)。For example, collection[0-1] [0-9] creates 20 collection names with leading zeros (collection01, ..02, ..03).

指定集合名稱之後,請選擇所需的集合輸送量 (400 RU 到 250,000 RU)。Once the collection name(s) have been specified, choose the desired throughput of the collection(s) (400 RUs to 250,000 RUs). 為了達到最佳的匯入效能,請選擇較高的輸送量。For best import performance, choose a higher throughput. 如需效能層級的詳細資訊,請參閱 Azure Cosmos DB 中的效能層級For more information about performance levels, see Performance levels in Azure Cosmos DB. 任何輸送量 >10000 RU 的集合匯入作業都需要資料分割索引鍵。Any import to collections with throughput >10,000 RUs require a partition key. 如果您選擇擁有 250,000 以上的 RU,您需要在入口網站中提出要求來提升您的帳戶。If you choose to have more than 250,000 RUs, you need to file a request in the portal to have your account increased.

注意

輸送量設定僅適用於集合或資料庫的建立。The throughput setting only applies to collection or database creation. 如果指定的集合已經存在,將不會修改其輸送量。If the specified collection already exists, its throughput won't be modified.

匯入到多個集合時,匯入工具支援以雜湊為基礎的分區化。When importing to more than one collection, the import tool supports hash-based sharding. 在此案例中,指定您想要用來做為資料分割索引鍵的文件屬性。In this scenario, specify the document property you wish to use as the Partition Key. (如果資料分割索引鍵是空白的,文件就會跨目標集合隨機進行分區化。)(If Partition Key is left blank, documents are sharded randomly across the target collections.)

您可以選擇性地指定在匯入期間,匯入來源中的哪些欄位應該作為 Azure Cosmos DB 文件識別碼屬性使用。You may optionally specify which field in the import source should be used as the Azure Cosmos DB document ID property during the import. (如果文件不包含這個屬性,則匯入工具會產生 GUID 做為識別碼屬性值。)(If documents don't have this property, then the import tool generates a GUID as the ID property value.)

匯入期間有數個可用的進階選項。There are a number of advanced options available during import. 首先,匯入日期類型時 (例如從 SQL Server 或 MongoDB),有三種匯入選項可供選擇:First, when importing date types (for example, from SQL Server or MongoDB), you can choose between three import options:

Azure Cosmos DB 日期時間匯入選項的螢幕擷取畫面

  • String (字串):保存為字串值String: Persist as a string value
  • Epoch:保存為 Epoch 數值Epoch: Persist as an Epoch number value
  • Both (兩者):同時保存字串和 Epoch 數值。Both: Persist both string and Epoch number values. 這個選項會建立子文件,例如:"date_joined": { "Value":"2013-10-21T21:17:25.2410000Z", "Epoch":1382390245 }This option creates a subdocument, for example: "date_joined": { "Value": "2013-10-21T21:17:25.2410000Z", "Epoch": 1382390245 }

Azure Cosmos DB 循序記錄匯入工具含有下列其他進階選項:The Azure Cosmos DB - Sequential record importer has the following additional advanced options:

  1. Number of Parallel Requests (平行要求數目):此工具預設為兩個平行要求。Number of Parallel Requests: The tool defaults to two parallel requests. 如果要匯入很小的文件,請考慮提高平行要求數目。If the documents to be imported are small, consider raising the number of parallel requests. 如果這個數字提高太多,則匯入可能會遭遇速率限制。If this number is raised too much, the import may experience rate limiting.
  2. Disable Automatic Id Generation (停用自動識別碼產生):如果要匯入的每個文件都有識別碼欄位,則選取此選項可以提升效能。Disable Automatic Id Generation: If every document to be imported has an ID field, then selecting this option can increase performance. 遺漏唯一識別碼欄位的文件不會被匯入。Documents missing a unique ID field aren't imported.
  3. Update Existing Documents (更新現有的文件):此工具預設在發生識別碼衝突時不會取代現有的文件。Update Existing Documents: The tool defaults to not replacing existing documents with ID conflicts. 選取此選項會允許在識別碼相符時覆寫現有的文件。Selecting this option allows overwriting existing documents with matching IDs. 對於會更新現有文件的已排定資料移轉來說,這項功能相當有用。This feature is useful for scheduled data migrations that update existing documents.
  4. Number of Retries on Failure (失敗時的重試次數):指定與 Azure Cosmos DB 的連線發生暫時性失敗 (例如網路連線中斷) 時的重試頻率。Number of Retries on Failure: Specifies how often to retry the connection to Azure Cosmos DB during transient failures (for example, network connectivity interruption).
  5. Retry Interval (重試間隔):指定與 Azure Cosmos DB 的連線發生暫時性失敗 (例如網路連線中斷) 時要等候的重試間隔時間。Retry Interval: Specifies how long to wait between retrying the connection to Azure Cosmos DB during transient failures (for example, network connectivity interruption).
  6. Connection Mode (連線模式):指定要與 Azure Cosmos DB 搭配使用的連線模式。Connection Mode: Specifies the connection mode to use with Azure Cosmos DB. 可用的選項包括:DirectTcp、DirectHttps 和閘道器。The available choices are DirectTcp, DirectHttps, and Gateway. 直接連線模式會比較快,但閘道器模式比較支援防火牆,因為它只會使用連接埠 443。The direct connection modes are faster, while the gateway mode is more firewall friendly as it only uses port 443.

Azure Cosmos DB 循序記錄匯入進階選項的螢幕擷取畫面

提示

匯入工具會預設 DirectTcp 連線模式。The import tool defaults to connection mode DirectTcp. 如果您遇到防火牆問題,請切換到閘道器連線模式,因為它只需要連接埠 443。If you experience firewall issues, switch to connection mode Gateway, as it only requires port 443.

指定索引編製原則Specify an indexing policy

當您允許移轉工具在匯入期間建立 Azure Cosmos DB SQL API 集合時,您可以指定集合的索引編製原則。When you allow the migration tool to create Azure Cosmos DB SQL API collections during import, you can specify the indexing policy of the collections. 在 Azure Cosmos DB 大量匯入和 Azure Cosmos DB 循序記錄選項的進階選項區段中,瀏覽至 [編製索引原則] 區段。In the advanced options section of the Azure Cosmos DB Bulk import and Azure Cosmos DB Sequential record options, navigate to the Indexing Policy section.

Azure Cosmos DB 編製索引原則進階選項的螢幕擷取畫面

使用索引編製原則進階選項,您可以選取索引編製原則檔案,以手動方式輸入索引編製原則,或從一組預設範本中選取 (以滑鼠右鍵按一下索引編製原則文字方塊)。Using the Indexing Policy advanced option, you can select an indexing policy file, manually enter an indexing policy, or select from a set of default templates (by right-clicking in the indexing policy textbox).

此工具提供的原則範本是:The policy templates the tool provides are:

  • 預設值。Default. 當您對字串執行相等查詢時,這是最佳的原則。This policy is best when you perform equality queries against strings. 最適合您使用 ORDER BY、範圍及數字的等號查詢時。It also works if you use ORDER BY, range, and equality queries for numbers. 這個原則的索引儲存空間負擔比範圍低。This policy has a lower index storage overhead than Range.
  • 範圍。Range. 當您在數字和字串上使用 ORDER BY、範圍及相等查詢時,這是最佳的原則。This policy is best when you use ORDER BY, range, and equality queries on both numbers and strings. 這個原則的索引儲存空間負擔比預設或雜湊高。This policy has a higher index storage overhead than Default or Hash.

Azure Cosmos DB 編製索引原則進階選項的螢幕擷取畫面

注意

如果未指定索引編製原則,則會套用預設原則。If you don't specify an indexing policy, then the default policy is applied. 如需編製索引原則的詳細資訊,請參閱 Azure Cosmos DB 編製索引原則For more information about indexing policies, see Azure Cosmos DB indexing policies.

匯出至 JSON 檔案Export to JSON file

Azure Cosmos DB JSON 匯出工具可讓您將任何可用的來源選項匯出至具有 JSON 文件陣列的 JSON 檔案。The Azure Cosmos DB JSON exporter allows you to export any of the available source options to a JSON file that has an array of JSON documents. 此工具會為您處理匯出作業。The tool handles the export for you. 或者,您可以選擇檢視產生的移轉命令,然後自己執行命令。Alternatively, you can choose to view the resulting migration command and run the command yourself. 產生的 JSON 檔案可能會儲存在本機或 Azure Blob 儲存體中。The resulting JSON file may be stored locally or in Azure Blob storage.

Azure Cosmos DB JSON 本機檔案匯出選項的螢幕擷取畫面

Azure Cosmos DB JSON Azure Blob 儲存體匯出選項的螢幕擷取畫面

您可以選擇性地選擇美化產生的 JSON。You may optionally choose to prettify the resulting JSON. 這個動作會增加產生文件的大小,但會使內容更容易閱讀。This action will increase the size of the resulting document while making the contents more human readable.

  • 標準 JSON 匯出Standard JSON export

    [{"id":"Sample","Title":"About Paris","Language":{"Name":"English"},"Author":{"Name":"Don","Location":{"City":"Paris","Country":"France"}},"Content":"Don's document in Azure Cosmos DB is a valid JSON document as defined by the JSON spec.","PageViews":10000,"Topics":[{"Title":"History of Paris"},{"Title":"Places to see in Paris"}]}]
    
  • 美化 JSON 匯出Prettified JSON export

      [
       {
      "id": "Sample",
      "Title": "About Paris",
      "Language": {
        "Name": "English"
      },
      "Author": {
        "Name": "Don",
        "Location": {
          "City": "Paris",
          "Country": "France"
        }
      },
      "Content": "Don's document in Azure Cosmos DB is a valid JSON document as defined by the JSON spec.",
      "PageViews": 10000,
      "Topics": [
        {
          "Title": "History of Paris"
        },
        {
          "Title": "Places to see in Paris"
        }
      ]
      }]
    

以下是將 JSON 檔案匯出至 Azure Blob 儲存體的命令列範例:Here is a command-line sample to export the JSON file to Azure Blob storage:

dt.exe /ErrorDetails:All /s:DocumentDB /s.ConnectionString:"AccountEndpoint=<CosmosDB Endpoint>;AccountKey=<CosmosDB Key>;Database=<CosmosDB database_name>" /s.Collection:<CosmosDB collection_name>
/t:JsonFile /t.File:"blobs://<Storage account key>@<Storage account name>.blob.core.windows.net:443/<Container_name>/<Blob_name>"
/t.Overwrite

進階組態Advanced configuration

在 [進階組態] 畫面中,指定您想要寫入所有錯誤的記錄檔位置。In the Advanced configuration screen, specify the location of the log file to which you would like any errors written. 下列規則會套用到此頁面:The following rules apply to this page:

  1. 如果未提供檔案名稱,則會在 [結果] 頁面上傳回所有錯誤。If a file name isn't provided, then all errors are returned on the Results page.

  2. 如果提供不含目錄的檔案名稱,則會在目前的環境目錄中建立 (或覆寫) 該檔案。If a file name is provided without a directory, then the file is created (or overwritten) in the current environment directory.

  3. 如果選取了現有的檔案,則會覆寫該檔案,沒有任何附加選項。If you select an existing file, then the file is overwritten, there's no append option.

  4. 然後,選擇是要記錄所有錯誤訊息、嚴重錯誤訊息,還是不記錄任何錯誤訊息。Then, choose whether to log all, critical, or no error messages. 最後,決定螢幕上傳輸訊息更新其進度的頻率。Finally, decide how frequently the on-screen transfer message is updated with its progress.

    進階設定畫面的螢幕擷取畫面

確認匯入設定及檢視命令列Confirm import settings and view command line

  1. 指定來源資訊、目標資訊與進階組態之後,請檢閱移轉摘要,以及檢視或複製所產生的移轉命令。After you specify the source information, target information, and advanced configuration, review the migration summary and view or copy the resulting migration command if you want. (複製命令對於自動匯入作業非常有用。)(Copying the command is useful to automate import operations.)

    摘要畫面的螢幕擷取畫面

    摘要畫面的螢幕擷取畫面

  2. 在您滿意來源和目標選項之後,請按一下 [匯入] 。Once you’re satisfied with your source and target options, click Import. 隨著匯入的處理,已耗用時間、傳送的計數,以及失敗的資訊 (如果您未在 [進階組態] 中提供檔案名稱) 都會隨之更新。The elapsed time, transferred count, and failure information (if you didn't provide a file name in the Advanced configuration) update as the import is in process. 完成後,您可以匯出結果 (例如處理任何匯入失敗)。Once complete, you can export the results (for example, to deal with any import failures).

    Azure Cosmos DB JSON 匯出選項的螢幕擷取畫面

  3. 重設所有的值或保留現有設定,也可以開始新的匯入。You may also start a new import by either resetting all values or keeping the existing settings. (例如,您可以選擇保留連接字串資訊、來源和目標選擇等等。)(For example, you may choose to keep connection string information, source and target choice, and more.)

    Azure Cosmos DB JSON 匯出選項的螢幕擷取畫面

後續步驟Next steps

在本教學課程中,您已完成下列工作:In this tutorial, you've done the following tasks:

  • 已安裝資料移轉工具Installed the Data Migration tool
  • 已從不同的資料來源匯入資料Imported data from different data sources
  • 已從 Azure Cosmos DB 匯出到 JSONExported from Azure Cosmos DB to JSON

您現在可以繼續進行下一個教學課程,了解如何使用 Azure Cosmos DB 查詢資料。You can now proceed to the next tutorial and learn how to query data using Azure Cosmos DB.