|
2 | 2 | title: Get started with partial document update
|
3 | 3 | titleSuffix: Azure Cosmos DB for NoSQL
|
4 | 4 | description: Learn how to use the partial document update feature with the .NET, Java, and Node SDKs for Azure Cosmos DB for NoSQL.
|
5 |
| -ms.author: sidandrews |
6 |
| -author: seesharprun |
| 5 | +author: AbhinavTrips |
| 6 | +ms.author: abtripathi |
7 | 7 | ms.service: cosmos-db
|
8 | 8 | ms.subservice: nosql
|
9 | 9 | ms.topic: how-to
|
10 |
| -ms.date: 04/03/2023 |
11 |
| -ms.custom: ignite-fall-2021, ignite-2022 |
| 10 | +ms.date: 05/23/2023 |
12 | 11 | ---
|
13 | 12 |
|
14 | 13 | # Get started with Azure Cosmos DB Partial Document Update
|
@@ -281,6 +280,57 @@ Support for Partial Document Update (Patch API) in the [Azure Cosmos DB JavaScri
|
281 | 280 |
|
282 | 281 | ---
|
283 | 282 |
|
| 283 | +## [Python (Preview)](#tab/python) |
| 284 | + |
| 285 | +Support for Partial Document Update (Patch API) in the [Azure Cosmos DB Python SDK](nosql/sdk-python.md) is available in Preview starting with version *4.4.0b2*. You can download it from the [pip Registry](https://pypi.org/project/azure-cosmos/4.4.0b2/). |
| 286 | +
|
| 287 | +> [!NOTE] |
| 288 | +> Find a complete Partial Document Update sample in the [python samples repository](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-cosmos/samples/document_management.py#L105C8-L122) on GitHub. |
| 289 | +
|
| 290 | +- Run a single patch operation: |
| 291 | + |
| 292 | + ```python |
| 293 | + operations = |
| 294 | + [ |
| 295 | + { op: 'replace', path: '/price', value: 355.45 } |
| 296 | + ] |
| 297 | + |
| 298 | + response = container.patch_item(item='e379aea5-63f5-4623-9a9b-4cd9b33b91d5', partition_key='road-bikes', patch_operations=operations) |
| 299 | + |
| 300 | + ``` |
| 301 | + |
| 302 | +- Combine multiple patch operations: |
| 303 | + |
| 304 | + ```python |
| 305 | + operations = |
| 306 | + [ |
| 307 | + { op: 'add', path: '/color', value: 'silver' }, |
| 308 | + { op: 'remove', path: '/used' } |
| 309 | + ] |
| 310 | + |
| 311 | + response = container.patch_item(item='e379aea5-63f5-4623-9a9b-4cd9b33b91d5', partition_key='road-bikes', patch_operations=operations) |
| 312 | + |
| 313 | + ``` |
| 314 | + |
| 315 | +- Use conditional patch syntax based on filter predicate: |
| 316 | + |
| 317 | + ```python |
| 318 | + filter = "from products p WHERE p.used = false" |
| 319 | + |
| 320 | + operations = |
| 321 | + [ |
| 322 | + { op: 'replace', path: '/price', value: 100.00 } |
| 323 | + ] |
| 324 | + |
| 325 | + try: |
| 326 | + container.patch_item(item='e379aea5-63f5-4623-9a9b-4cd9b33b91d5', partition_key='road-bikes', patch_operations=operations, filter_predicate=filter) |
| 327 | + except exceptions.CosmosHttpResponseError as e: |
| 328 | + print('\nError occured. {0}'.format(e.message)) |
| 329 | + |
| 330 | + ``` |
| 331 | + |
| 332 | +--- |
| 333 | + |
284 | 334 | ## Support for server-side programming
|
285 | 335 |
|
286 | 336 | Partial Document Update operations can also be [executed on the server-side](stored-procedures-triggers-udfs.md) using stored procedures, triggers, and user-defined functions.
|
|
0 commit comments