Search⌘ K

Introduction to the JavaScript API

Learn to use the Cosmos DB JavaScript API to implement server-side logic with stored procedures and triggers. Understand how to access and manipulate containers, documents, and attachments using the context methods. This lesson helps you perform operations beyond SDK capabilities, optimizing performance and extending functionality.

Introduction

A valuable feature of Cosmos DB is its ability to run JavaScript code in its engine. When possible, it’s always advisable to use the SDKs. However, we can use the JavaScript API when we need more features or performance.

More specifically, we can use it in the following ways:

  • Stored procedures

  • Triggers

The context

Usually, the context is the most important instance when a function runs in the engine. We can get a reference to it with the getContext() method.

We can access the following using the context ...