Reference

Endpoint Create a document in the container


Name

create_document

Description

Insert JSON document in Cosmos DB Container. [API reference]

Related Tables

[Dynamic Table]

Parameters

Parameter Required Options
Name: Table

Label: Table Name (Case-Sensitive)

YES
Name: Database

Label: Database Name (keep blank to use default) Case-Sensitive

Leave blank to use default DB set on connection screen
Name: Document

Label: Document

Name: PartitionKey

Label: Partition Key Value (default is supplied Id)

The partition key value for the document. Must be included if and only if the collection is created with a partitionKey definition
Option Value
Default .
SingleKeyValue ["someValue1"]
MultiKeyValue ["some_value1","some_value2" ]
Name: Upsert

Label: Enable Upsert Mode (update if document found)

Option Value
true true
false false

Output Columns

Label Data Type (SSIS) Data Type (SQL) Length Description
id DT_WSTR nvarchar(4000) 4000
_rid DT_WSTR nvarchar(4000) 4000
_ts DT_I8 bigint
http_status DT_I4 int
If the column you are looking for is missing, consider customizing Cosmos DB Connector.

Input Columns

Label Data Type (SSIS) Data Type (SQL) Length Description
PartitionKey DT_WSTR nvarchar(4000) 4000
Document DT_NTEXT nvarchar(MAX)
Required columns that you need to supply are bolded.

Examples

SSIS

Use Cosmos DB Connector in API Source or in API Destination SSIS Data Flow components to read or write data.

API Source

API Source - Cosmos DB
Connect to your Azure Cosmos DB databases to read, query, create, update, and delete documents and more!
Cosmos DB
Create a document in the container
There are no parameters to configure.
SSIS API Source - Read from table or endpoint

API Destination

This Endpoint belongs to the [Dynamic Table] table, therefore it is better to use it, instead of accessing the endpoint directly. Use this table and table-operation pair to create a document in the container:

API Destination - Cosmos DB
Connect to your Azure Cosmos DB databases to read, query, create, update, and delete documents and more!
Cosmos DB
[Dynamic Table]
Insert
There are no parameters to configure.
SSIS API Destination - Access table operation

ODBC application

Use these SQL queries in your ODBC application data source:

Create a new document with Partition Key supplied

Loads a new document into specified container with partition key. If you created container with Partition Key requirement then must supply it. Partition Key must be valid value from Document Attribute used as Partition Key.

INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
'["user2"]', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
'{
  "id": "user2",
  "name": "John Doe",
  "email": "jdoe@contoso.com",
  "phone": ["12345"],
  "level": "platinum"
}'
)
WITH(Upsert='true')

Create a new document from a file path (Upload from local disk file)

Loads a new document into specified container from local file path. File path must start with @ symbol

INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
'["user2"]', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
'@c:\data\order.json'   --path must start with @ symbol
)
WITH(Upsert='true', IsMultiPart=1)

Upsert a document (Insert or Update if exists)

Upsert a document (Update if id exists else create new one).

INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
'["user2"]', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
'{
  "id": "user2",
  "name": "John Doe",
  "email": "jdoe@contoso.com",
  "phone": ["12345"],
  "level": "platinum"
}')
 WITH(Upsert='true')

create_document endpoint belongs to [Dynamic Table] table(s), and can therefore be used via those table(s).

SQL Server

Use these SQL queries in SQL Server after you create a data source in Data Gateway:

Create a new document with Partition Key supplied

Loads a new document into specified container with partition key. If you created container with Partition Key requirement then must supply it. Partition Key must be valid value from Document Attribute used as Partition Key.

DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
''["user2"]'', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
''{
  "id": "user2",
  "name": "John Doe",
  "email": "jdoe@contoso.com",
  "phone": ["12345"],
  "level": "platinum"
}''
)
WITH(Upsert=''true'')';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

Create a new document from a file path (Upload from local disk file)

Loads a new document into specified container from local file path. File path must start with @ symbol

DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
''["user2"]'', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
''@c:\data\order.json''   --path must start with @ symbol
)
WITH(Upsert=''true'', IsMultiPart=1)';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

Upsert a document (Insert or Update if exists)

Upsert a document (Update if id exists else create new one).

DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
''["user2"]'', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
''{
  "id": "user2",
  "name": "John Doe",
  "email": "jdoe@contoso.com",
  "phone": ["12345"],
  "level": "platinum"
}'')
 WITH(Upsert=''true'')';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

create_document endpoint belongs to [Dynamic Table] table(s), and can therefore be used via those table(s).