Overview of Stored Procedures
Learn how we can use stored procedure to execute complex transactions on Cosmos DB.
Introduction
Stored procedures are JavaScript functions that can run on the database engine when we manually request them, and unlike user-defined functions, they cannot be used in queries.
We can fully utilize the JavaScript API to interact with documents.
Note: All inputs are strings. If we need complex objects, we have to use
JSON.parse
.
Transactions
Stored procedures run in a transactional scope. All the changes are rolled back if any exception happens in the function. In Cosmos DB, transactions exist only within a logical partition, so we need to specify a partition key when we run a stored procedure.
Replacing items
For example, we can use a function that replaces two items on the same logical partition.
Get hands-on with 1400+ tech skills courses.