Azure Cosmos DB
Store data in Azure Cosmos DB NoSQL API documents.
This driver stores KV information in a NoSQL API Cosmos DB collection as documents. It uses the id
field as the key and adds value
and modified
fields to the document.
To use it, you will need to install @azure/cosmos
and @azure/identity
in your project:
npm i @azure/cosmos @azure/identity
Usage:
import { createStorage } from "unstorage";
import azureCosmos from "unstorage/drivers/azure-cosmos";
const storage = createStorage({
driver: azureCosmos({
endpoint: "ENDPOINT",
accountKey: "ACCOUNT_KEY",
}),
});
Authentication:
DefaultAzureCredential
: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate.
โ ๏ธ Make sure that your Managed Identity or personal account has at leastCosmos DB Built-in Data Contributor
role assigned to it. If you already areContributor
orOwner
on the resource it should also be enough, but does not accomplish a model of least privilege.accountKey
: CosmosDB account key. If not provided, the driver will use the DefaultAzureCredential (recommended).
Options:
endpoint
(required): CosmosDB endpoint in the format ofhttps://<account>.documents.azure.com:443/
.accountKey
: CosmosDB account key. If not provided, the driver will use the DefaultAzureCredential (recommended).databaseName
: The name of the database to use. Defaults tounstorage
.containerName
: The name of the container to use. Defaults tounstorage
.