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
Connect to your Azure Cosmos DB databases to read, query, create, update, and delete documents and more!
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
Connect to your Azure Cosmos DB databases to read, query, create, update, and delete documents and more!
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 (replace) a document (By default Full replace)

Update a document for a specified Document Id.

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 a document (Patch)

Update one or more attributes in a document using PATCH method for a specified Document Id.

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 a document (Patch) from a file path (Upload from local disk file)

Update one or more attributes in a document using PATCH method for a specified Document Id read operations from local disk file.

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 (replace) a document (By default Full replace)

Update a document for a specified Document Id.

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 a document (Patch)

Update one or more attributes in a document using PATCH method for a specified Document Id.

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 a document (Patch) from a file path (Upload from local disk file)

Update one or more attributes in a document using PATCH method for a specified Document Id read operations from local disk file.

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).