Reference

Endpoint Update Document in the Container


Name

update_document

Description

Update full or part of the document in Cosmos DB Container. [API reference]

Related Tables

[Dynamic Table]

Parameters

Parameter Required Options
Name: Table

Label: Table Name (Case-Sensitive)

YES
Name: Id

Label: Document Id

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

Full Document if RequestMethod=PUT else Partial 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
RequestMethod DT_WSTR nvarchar(4000) 4000
PartitionKey DT_WSTR nvarchar(4000) 4000
Id 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
Update 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 update 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]
Update
There are no parameters to configure.
SSIS API Destination - Access table operation

ODBC application

Use these SQL queries in your ODBC application data source:

Update document (full replace)

<p>Replaces the entire document for the given <code>Id</code>. Set <code>PartitionKey</code> and <code>Document</code> to the full JSON body. The default request method is PUT (full replace). Use this when you want to overwrite the document completely; for changing only some fields use the partial update (PATCH) example.</p>

UPDATE TestContainer 
SET  
 PartitionKey='["user2"]'
,Document=
'{
  "id" : "user2",
  "name": "John Doe at <<FUN_NOW>>",
  "email": "jdoe@contoso.com",
  "phone": ["<<FUN_TODAY>>"],
  "level": "platinum"
}'
Where Id='user2'

Partial update document (PATCH)

<p>Updates only specified attributes using the PATCH method. Set <code>RequestMethod</code> to PATCH in <code>WITH</code> and supply a <code>Document</code> body with a JSON Patch <code>operations</code> array (e.g. set, add, remove, incr, move). Use when you need to change a few fields without sending the full document.</p><p>For operations and syntax see <a href="https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update">partial document update</a> and <a href="https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document">REST API</a>.</p>

UPDATE TestContainer 
SET  
 PartitionKey='["user2"]'
,Document=
'{
  "operations": [
     { "op": "set", "path": "/name", "value": "updated name" }
	,{ "op": "set", "path": "/email", "value": "updated@email.com" }
  ]
}'
Where Id='user2'
WITH(
		RequestMethod='PATCH' --Partial Replace (change name and email only)
    )
	
/*
Example Document Operations
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update
https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document

[
  { "op": "add", "path": "/color", "value": "silver" },
  { "op": "remove", "path": "/used" },
  { "op": "set", "path": "/price", "value": 355.45 }
  { "op": "incr", "path": "/inventory/quantity", "value": 10 },
  { "op": "add", "path": "/tags/-", "value": "featured-bikes" },
  { "op": "move", "from": "/color", "path": "/inventory/color" }
]

*/

Partial update document (PATCH) from file

<p>Same as partial update (PATCH) but the JSON Patch operations are read from a local file. The path must start with the <code>@</code> symbol; set <code>IsMultiPart=1</code> in <code>WITH</code> to enable file upload. Useful when the patch payload is large or generated externally.</p><p>For operations and syntax see <a href="https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update">partial document update</a> and <a href="https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document">REST API</a>.</p>

UPDATE TestContainer 
SET  
 PartitionKey='["user2"]'
,Document='@c:\temp\b.txt'  --path must start with @ symbol
Where Id='user2'
WITH(
		 RequestMethod='PATCH' --Partial Replace (change name and email only)
	    ,IsMultiPart=1 --this enables file upload	
    )
	
/*
Example Document Operations
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update
https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document

[
  { "op": "add", "path": "/color", "value": "silver" },
  { "op": "remove", "path": "/used" },
  { "op": "set", "path": "/price", "value": 355.45 }
  { "op": "incr", "path": "/inventory/quantity", "value": 10 },
  { "op": "add", "path": "/tags/-", "value": "featured-bikes" },
  { "op": "move", "from": "/color", "path": "/inventory/color" }
]

*/

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

Update document (full replace)

<p>Replaces the entire document for the given <code>Id</code>. Set <code>PartitionKey</code> and <code>Document</code> to the full JSON body. The default request method is PUT (full replace). Use this when you want to overwrite the document completely; for changing only some fields use the partial update (PATCH) example.</p>

DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE TestContainer 
SET  
 PartitionKey=''["user2"]''
,Document=
''{
  "id" : "user2",
  "name": "John Doe at <<FUN_NOW>>",
  "email": "jdoe@contoso.com",
  "phone": ["<<FUN_TODAY>>"],
  "level": "platinum"
}''
Where Id=''user2''';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

Partial update document (PATCH)

<p>Updates only specified attributes using the PATCH method. Set <code>RequestMethod</code> to PATCH in <code>WITH</code> and supply a <code>Document</code> body with a JSON Patch <code>operations</code> array (e.g. set, add, remove, incr, move). Use when you need to change a few fields without sending the full document.</p><p>For operations and syntax see <a href="https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update">partial document update</a> and <a href="https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document">REST API</a>.</p>

DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE TestContainer 
SET  
 PartitionKey=''["user2"]''
,Document=
''{
  "operations": [
     { "op": "set", "path": "/name", "value": "updated name" }
	,{ "op": "set", "path": "/email", "value": "updated@email.com" }
  ]
}''
Where Id=''user2''
WITH(
		RequestMethod=''PATCH'' --Partial Replace (change name and email only)
    )
	
/*
Example Document Operations
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update
https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document

[
  { "op": "add", "path": "/color", "value": "silver" },
  { "op": "remove", "path": "/used" },
  { "op": "set", "path": "/price", "value": 355.45 }
  { "op": "incr", "path": "/inventory/quantity", "value": 10 },
  { "op": "add", "path": "/tags/-", "value": "featured-bikes" },
  { "op": "move", "from": "/color", "path": "/inventory/color" }
]

*/';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

Partial update document (PATCH) from file

<p>Same as partial update (PATCH) but the JSON Patch operations are read from a local file. The path must start with the <code>@</code> symbol; set <code>IsMultiPart=1</code> in <code>WITH</code> to enable file upload. Useful when the patch payload is large or generated externally.</p><p>For operations and syntax see <a href="https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update">partial document update</a> and <a href="https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document">REST API</a>.</p>

DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE TestContainer 
SET  
 PartitionKey=''["user2"]''
,Document=''@c:\temp\b.txt''  --path must start with @ symbol
Where Id=''user2''
WITH(
		 RequestMethod=''PATCH'' --Partial Replace (change name and email only)
	    ,IsMultiPart=1 --this enables file upload	
    )
	
/*
Example Document Operations
https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update
https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document

[
  { "op": "add", "path": "/color", "value": "silver" },
  { "op": "remove", "path": "/used" },
  { "op": "set", "path": "/price", "value": 355.45 }
  { "op": "incr", "path": "/inventory/quantity", "value": 10 },
  { "op": "add", "path": "/tags/-", "value": "featured-bikes" },
  { "op": "move", "from": "/color", "path": "/inventory/color" }
]

*/';

EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];

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