Skip to content

Commit a287b47

Browse files
Merge pull request #231113 from seesharprun/cosmos-how-to-use-stored-procedures-triggers-udfs-code-review
Cosmos DB | Add note about client objects to NoSQL server-side programming
2 parents 3b02bfd + 28f9e5c commit a287b47

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

articles/cosmos-db/nosql/how-to-use-stored-procedures-triggers-udfs.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
---
2-
title: Register and use stored procedures, triggers, and user-defined functions in Azure Cosmos DB SDKs
2+
title: Use stored procedures, triggers, and UDFs in SDKs
3+
titleSuffix: Azure Cosmos DB
34
description: Learn how to register and call stored procedures, triggers, and user-defined functions using the Azure Cosmos DB SDKs.
45
author: seesharprun
56
ms.service: cosmos-db
67
ms.subservice: nosql
7-
ms.topic: how-to
8-
ms.date: 03/09/2023
8+
ms.topic: conceptual
9+
ms.date: 03/16/2023
910
ms.author: sidandrews
1011
ms.reviewer: jucocchi
1112
ms.devlang: csharp, java, javascript, python
1213
ms.custom: devx-track-python, devx-track-js, devx-track-csharp
1314
---
1415

1516
# How to register and use stored procedures, triggers, and user-defined functions in Azure Cosmos DB
17+
1618
[!INCLUDE[NoSQL](../includes/appliesto-nosql.md)]
1719

1820
The API for NoSQL in Azure Cosmos DB supports registering and invoking stored procedures, triggers, and user-defined functions (UDFs) written in JavaScript. After you define one or more stored procedures, triggers, or user-defined functions, you can load and view them in the [Azure portal](https://portal.azure.com/) by using Data Explorer.
@@ -22,10 +24,13 @@ You can use the API for NoSQL SDK across multiple platforms including [.NET v2 (
2224
| SDK | Getting started |
2325
| :--- | :--- |
2426
| .NET v3 | [Quickstart: Azure Cosmos DB for NoSQL client library for .NET](quickstart-dotnet.md) |
25-
| Java | [Quickstart: Build a Java app to manage Azure Cosmos DB for NoSQL data](quickstart-java.md)
27+
| Java | [Quickstart: Build a Java app to manage Azure Cosmos DB for NoSQL data](quickstart-java.md) |
2628
| JavaScript | [Quickstart: Azure Cosmos DB for NoSQL client library for Node.js](quickstart-nodejs.md) |
2729
| Python | [Quickstart: Azure Cosmos DB for NoSQL client library for Python](quickstart-python.md) |
2830

31+
> [!IMPORTANT]
32+
> The following code samples assume that you have already have `client` and `container` variables. If you need to create those variables, refer to the appropriate quickstart for your platform.
33+
2934
## How to run stored procedures
3035

3136
Stored procedures are written using JavaScript. They can create, update, read, query, and delete items within an Azure Cosmos DB container. For more information, see [How to write stored procedures](how-to-write-stored-procedures-triggers-udfs.md#stored-procedures).
@@ -232,18 +237,18 @@ result = container.scripts.execute_stored_procedure(sproc=created_sproc,params=[
232237

233238
---
234239

235-
## How to run pre-triggers
240+
## <a id="how-to-run-pre-triggers"></a>How to run pretriggers
236241

237-
The following examples show how to register and call a pre-trigger by using the Azure Cosmos DB SDKs. For the source of this pre-trigger example, saved as *trgPreValidateToDoItemTimestamp.js*, see [Pre-triggers](how-to-write-stored-procedures-triggers-udfs.md#pre-triggers).
242+
The following examples show how to register and call a pretrigger by using the Azure Cosmos DB SDKs. For the source of this pretrigger example, saved as *trgPreValidateToDoItemTimestamp.js*, see [Pretriggers](how-to-write-stored-procedures-triggers-udfs.md#pre-triggers).
238243

239-
When you run an operation by specifying `PreTriggerInclude` and then passing the name of the trigger in a `List` object, pre-triggers are passed in the `RequestOptions` object.
244+
When you run an operation by specifying `PreTriggerInclude` and then passing the name of the trigger in a `List` object, pretriggers are passed in the `RequestOptions` object.
240245

241246
> [!NOTE]
242247
> Even though the name of the trigger is passed as a `List`, you can still run only one trigger per operation.
243248
244249
### [.NET SDK v2](#tab/dotnet-sdk-v2)
245250

246-
The following code shows how to register a pre-trigger using the .NET SDK v2:
251+
The following code shows how to register a pretrigger using the .NET SDK v2:
247252

248253
```csharp
249254
string triggerId = "trgPreValidateToDoItemTimestamp";
@@ -258,7 +263,7 @@ Uri containerUri = UriFactory.CreateDocumentCollectionUri("myDatabase", "myConta
258263
await client.CreateTriggerAsync(containerUri, trigger);
259264
```
260265

261-
The following code shows how to call a pre-trigger using the .NET SDK v2:
266+
The following code shows how to call a pretrigger using the .NET SDK v2:
262267

263268
```csharp
264269
dynamic newItem = new
@@ -276,7 +281,7 @@ await client.CreateDocumentAsync(containerUri, newItem, requestOptions);
276281

277282
### [.NET SDK v3](#tab/dotnet-sdk-v3)
278283

279-
The following code shows how to register a pre-trigger using the .NET SDK v3:
284+
The following code shows how to register a pretrigger using the .NET SDK v3:
280285

281286
```csharp
282287
await client.GetContainer("database", "container").Scripts.CreateTriggerAsync(new TriggerProperties
@@ -288,7 +293,7 @@ await client.GetContainer("database", "container").Scripts.CreateTriggerAsync(ne
288293
});
289294
```
290295

291-
The following code shows how to call a pre-trigger using the .NET SDK v3:
296+
The following code shows how to call a pretrigger using the .NET SDK v3:
292297

293298
```csharp
294299
dynamic newItem = new
@@ -304,7 +309,7 @@ await client.GetContainer("database", "container").CreateItemAsync(newItem, null
304309

305310
### [Java SDK](#tab/java-sdk)
306311

307-
The following code shows how to register a pre-trigger using the Java SDK:
312+
The following code shows how to register a pretrigger using the Java SDK:
308313

309314
```java
310315
CosmosTriggerProperties definition = new CosmosTriggerProperties(
@@ -319,7 +324,7 @@ CosmosTriggerResponse response = container
319324
.createTrigger(definition);
320325
```
321326

322-
The following code shows how to call a pre-trigger using the Java SDK:
327+
The following code shows how to call a pretrigger using the Java SDK:
323328

324329
```java
325330
ToDoItem item = new ToDoItem();
@@ -338,7 +343,7 @@ CosmosItemResponse<ToDoItem> response = container.createItem(item, options);
338343

339344
### [JavaScript SDK](#tab/javascript-sdk)
340345

341-
The following code shows how to register a pre-trigger using the JavaScript SDK:
346+
The following code shows how to register a pretrigger using the JavaScript SDK:
342347

343348
```javascript
344349
const container = client.database("myDatabase").container("myContainer");
@@ -351,7 +356,7 @@ await container.scripts.triggers.create({
351356
});
352357
```
353358

354-
The following code shows how to call a pre-trigger using the JavaScript SDK:
359+
The following code shows how to call a pretrigger using the JavaScript SDK:
355360

356361
```javascript
357362
const container = client.database("myDatabase").container("myContainer");
@@ -366,7 +371,7 @@ await container.items.create({
366371

367372
### [Python SDK](#tab/python-sdk)
368373

369-
The following code shows how to register a pre-trigger using the Python SDK:
374+
The following code shows how to register a pretrigger using the Python SDK:
370375

371376
```python
372377
import azure.cosmos.cosmos_client as cosmos_client
@@ -392,7 +397,7 @@ container = database.get_container_client(container_name)
392397
trigger = container.scripts.create_trigger(trigger_definition)
393398
```
394399

395-
The following code shows how to call a pre-trigger using the Python SDK:
400+
The following code shows how to call a pretrigger using the Python SDK:
396401

397402
```python
398403
item = {'category': 'Personal', 'name': 'Groceries',

0 commit comments

Comments
 (0)