Reference

Endpoint Upsert a document in the container


Name

upsert_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: Upsert

Label: Upsert

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" ]

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
Read and write Azure Cosmos DB data effortlessly. Query, integrate, and manage databases, containers, documents, and users — almost no coding required.
Cosmos DB
Upsert a document in the container
Optional Parameters
Upsert true
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 upsert a document in the container:

API Destination - Cosmos DB
Read and write Azure Cosmos DB data effortlessly. Query, integrate, and manage databases, containers, documents, and users — almost no coding required.
Cosmos DB
[Dynamic Table]
Upsert
Optional Parameters
Upsert true
SSIS API Destination - Access table operation

ODBC application

Use these SQL queries in your ODBC application data source:

Upsert document using UPSERT keyword

<p>Same as upsert with <code>INSERT</code> and the <code>Upsert</code> option in <code>WITH</code>, but uses the <code>UPSERT INTO</code> syntax so you do not need the <code>WITH</code> clause. Use whichever style you prefer; behavior is the same.</p>

UPSERT 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"
}')

upsert_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:

Upsert document using UPSERT keyword

<p>Same as upsert with <code>INSERT</code> and the <code>Upsert</code> option in <code>WITH</code>, but uses the <code>UPSERT INTO</code> syntax so you do not need the <code>WITH</code> clause. Use whichever style you prefer; behavior is the same.</p>

DECLARE @MyQuery NVARCHAR(MAX) = 'UPSERT 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"
}'')';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

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