Skip to content

Commit e50cf86

Browse files
Merge pull request #227432 from seesharprun/cosmos-server-side-js-tips
Cosmos DB | Implement tips for server-side JS articles
2 parents 5458b0d + 0e5bae9 commit e50cf86

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ To call a stored procedure, trigger, and user-defined function, you need to regi
2121

2222
> [!NOTE]
2323
> For partitioned containers, when executing a stored procedure, a partition key value must be provided in the request options. Stored procedures are always scoped to a partition key. Items that have a different partition key value will not be visible to the stored procedure. This also applied to triggers as well.
24-
> [!Tip]
24+
25+
> [!NOTE]
26+
> Server-side JavaScript features including stored procedures, triggers, and user-defined functions do not support importing modules.
27+
28+
> [!TIP]
2529
> Azure Cosmos DB supports deploying containers with stored procedures, triggers and user-defined functions. For more information see [Create an Azure Cosmos DB container with server-side functionality.](./manage-with-templates.md#create-sproc)
2630
2731
## <a id="stored-procedures"></a>How to write stored procedures

articles/cosmos-db/nosql/query/udfs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ However, we recommending avoiding UDFs when:
2929

3030
If you must use the same UDF multiple times in a query, you should reference the UDF in a [subquery](subquery.md#evaluate-once-and-reference-many-times), allowing you to use a JOIN expression to evaluate the UDF once but reference it many times.
3131

32+
> [!NOTE]
33+
> Server-side JavaScript features including user-defined functions do not support importing modules.
34+
3235
## Examples
3336

3437
The following example registers a UDF under an item container in the Azure Cosmos DB database. The example creates a UDF whose name is `REGEX_MATCH`. It accepts two JSON string values, `input` and `pattern`, and checks if the first matches the pattern specified in the second using JavaScript's `string.match()` function.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Writing stored procedures, triggers, and user-defined functions (UDFs) in JavaSc
3737
> [!TIP]
3838
> Stored procedures are best suited for operations that are write-heavy and require a transaction across a partition key value. When deciding whether to use stored procedures, optimize around encapsulating the maximum amount of writes possible. Generally speaking, stored procedures are not the most efficient means for doing large numbers of read or query operations, so using stored procedures to batch large numbers of reads to return to the client will not yield the desired benefit. For best performance, these read-heavy operations should be done on the client-side, using the Azure Cosmos DB SDK.
3939
40+
> [!NOTE]
41+
> Server-side JavaScript features including stored procedures, triggers, and user-defined functions do not support importing modules.
42+
4043
## Transactions
4144

4245
Transaction in a typical database can be defined as a sequence of operations performed as a single logical unit of work. Each transaction provides **ACID property guarantees**. ACID is a well-known acronym that stands for: **A**tomicity, **C**onsistency, **I**solation, and **D**urability.
@@ -51,6 +54,9 @@ Transaction in a typical database can be defined as a sequence of operations per
5154

5255
In Azure Cosmos DB, JavaScript runtime is hosted inside the database engine. Hence, requests made within the stored procedures and the triggers execute in the same scope as the database session. This feature enables Azure Cosmos DB to guarantee ACID properties for all operations that are part of a stored procedure or a trigger. For examples, see [how to implement transactions](how-to-write-stored-procedures-triggers-udfs.md#transactions) article.
5356

57+
> [!TIP]
58+
> For transaction support in Azure Cosmos DB for NoSQL, you can also implement a transactional batch using your preferred client SDK. For more information, see [Transactional batch operations in Azure Cosmos DB for NoSQL](transactional-batch.md).
59+
5460
### Scope of a transaction
5561

5662
Stored procedures are associated with an Azure Cosmos DB container and stored procedure execution is scoped to a logical partition key. Stored procedures must include a logical partition key value during execution that defines the logical partition for the scope of the transaction. For more information, see [Azure Cosmos DB partitioning](../partitioning-overview.md) article.

0 commit comments

Comments
 (0)