Skip to content

Add docs for CosmosDB preview emulator #2654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/database/includes/cosmos-app-host.md
Original file line number Diff line number Diff line change
@@ -231,3 +231,27 @@ var cosmos = builder.AddAzureCosmosDB("cosmos-db").RunAsEmulator(
```

The preceding code configures the Cosmos DB emulator container to have a partition count of `100`. This is a shorthand for setting the `AZURE_COSMOS_EMULATOR_PARTITION_COUNT` environment variable.

#### Use Linux-based emulator (preview)

The [next generation of the Azure Cosmos DB emulator](/azure/cosmos-db/emulator-linux) is entirely Linux-based and is available as a Docker container. It supports running on a wide variety of processors and operating systems.

To use the preview version of the Cosmos DB emulator, call the <xref:Aspire.Hosting.AzureCosmosExtensions.RunAsPreviewEmulator*> method. Since this feature is in preview, you need to explicitly opt into the preview feature by suppressing the `ASPIRECOSMOSDB001` experimental diagnostic.

The preview emulator also supports exposing a "Data Explorer" endpoint which allows you to view the data stored in the Cosmos DB emulator via a web UI. To enable the Data Explorer, call the <xref:Aspire.Hosting.AzureCosmosExtensions.WithDataExplorer*> method.

```csharp
#pragma warning disable ASPIRECOSMOSDB001

var builder = DistributedApplication.CreateBuilder(args);

var cosmos = builder.AddAzureCosmosDB("cosmos-db").RunAsPreviewEmulator(
emulator =>
{
emulator.WithDataExplorer();
});

// After adding all resources, run the app...
```

The preceding code configures the Linux-based preview Cosmos DB emulator container, with the Data Explorer endpoint, to use at run time.
22 changes: 22 additions & 0 deletions docs/diagnostics/overview.md
Original file line number Diff line number Diff line change
@@ -74,3 +74,25 @@ Alternatively, you can suppress this diagnostic with preprocessor directive by a
// API that is causing the warning.
#pragma warning restore ASPIREHOSTINGPYTHON001
```

## ASPIRECOSMOSDB001

<span id="ASPIRECOSMOSDB001"></span>

.NET Aspire provides a way to use the CosmosDB Linux-based (preview) emulator. Since this emulator is in preview and the shape of this API is expected to change in the future, it has been marked as _Experimental_. To suppress the compiler error/warning use the following code:

To suppress this diagnostic with the `SuppressMessageAttribute`, add the following code to your project file:

```xml
<PropertyGroup>
<NoWarn>$(NoWarn);ASPIRECOSMOSDB001</NoWarn>
<PropertyGroup>
```

Alternatively, you can suppress this diagnostic with preprocessor directive by adding the following code to your project:

```csharp
#pragma warning disable ASPIRECOSMOSDB001
// API that is causing the warning.
#pragma warning restore ASPIRECOSMOSDB001
```