Endpoint Upsert a document in the container
Name
upsert_document
Description
Insert JSON document in Cosmos DB Container. [API reference]
Related Tables
Parameters
Parameter | Required | Options | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Name:
Label: Table Name (Case-Sensitive) |
YES | |||||||||
Name:
Label: Upsert |
||||||||||
Name:
Label: Database Name (keep blank to use default) Case-Sensitive Leave blank to use default DB set on connection screen |
||||||||||
Name:
Label: Document |
||||||||||
Name:
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 |
|
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
|
Input Columns
Label | Data Type (SSIS) | Data Type (SQL) | Length | Description |
---|---|---|---|---|
PartitionKey |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
Document |
DT_NTEXT
|
nvarchar(MAX)
|
Examples
SSIS
Use Cosmos DB Connector in API Source or in API Destination SSIS Data Flow components to read or write data.
API Source
Optional Parameters | |
---|---|
Upsert | true |

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:
Optional Parameters | |
---|---|
Upsert | true |

ODBC application
Use these SQL queries in your ODBC application data source:
Upsert a document (Insert or Update if exists) - Use UPSERT Keyword rather than WITH option
Upsert a document (Update if id exists else create new one). This one uses UPSERT KEY word slight simpler syntax becuase you dont need WITH clause like INSERT... WITH(UPSERT='true') example.
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 a document (Insert or Update if exists) - Use UPSERT Keyword rather than WITH option
Upsert a document (Update if id exists else create new one). This one uses UPSERT KEY word slight simpler syntax becuase you dont need WITH clause like INSERT... WITH(UPSERT='true') example.
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).