Tutorial: Sharing Azure Spatial Anchors across sessions and devices with an Azure Cosmos DB back end

This tutorial is a continuation of sharing Azure Spatial Anchors across sessions and devices. It will guide you through the process of adding a few more capabilities to make Azure Cosmos DB serve as the back-end storage while sharing azure spatial anchors across sessions and devices.

GIF illustrating object persistence

It's worth noting that, though you'll be using Unity and Azure Cosmos DB in this tutorial, it's just to give you an example of how to share Spatial Anchors identifiers across devices. You can user other languages and back-end technologies to achieve the same goal. Also, the ASP.NET Core web app used in this tutorial requires the .NET Core 2.2 SDK. It runs fine on Web Apps for Windows, but it won't currently run on Web Apps for Linux.

Create a database account

Add an Azure Cosmos Database to the resource group you created earlier.

  1. In a new browser window, sign in to the Azure portal.

  2. In the left navigation pane, select Create a resource. Select Databases and then select Azure Cosmos DB.

    Screenshot of the Azure portal, highlighting More Services, and Azure Cosmos DB

  3. On the Create Azure Cosmos DB Account page, enter the settings for the new Azure Cosmos DB account:

    Setting Value Description
    Subscription Your subscription Select the Azure subscription that you want to use for this Azure Cosmos DB account.
    Resource Group Create new

    Then enter the same unique name as provided in ID
    Select Create new. Then enter a new resource group name for your account. For simplicity, use the same name as your ID.
    Account Name Enter a unique name Enter a unique name to identify your Azure Cosmos DB account.

    The ID can use only lowercase letters, numbers, and the hyphen (-) character. It must be between 3 and 31 characters long.
    API Azure Table The API determines the type of account to create. Azure Cosmos DB provides five APIs: Core(SQL) for document databases, Gremlin for graph databases, MongoDB for document databases, Azure Table, and Cassandra. Currently, you must create a separate account for each API.

    Select Azure Table because in this quickstart you're creating a table that works with the Table API.

    Learn more about the Table API.
    Location Select the region closest to your users Select a geographic location to host your Azure Cosmos DB account. Use the location that's closest to your users to give them the fastest access to data.

    You can leave the Geo-Redundancy and Multi-region Writes options at their default values (Disable) to avoid additional RU charges. You can skip the Network and Tags sections.

  4. Select Review+Create. After the validation is complete, select Create to create the account.

    The new account page for Azure Cosmos DB

  5. It takes a few minutes to create the account. You'll see a message that states Your deployment is underway. Wait for the deployment to finish and then select Go to resource.

    The Azure portal notifications pane

Copy the Connection String because you'll need it.

Make minor changes to the SharingService files

In Solution Explorer, open SharingService\Startup.cs.

Locate #define INMEMORY_DEMO at the top of the file and comment that line out. Save the file.

In Solution Explorer, open SharingService\appsettings.json.

Locate the StorageConnectionString property, and set the value to be the same as the Connection String value that you copied in the create a database account step. Save the file.

You can publish the Sharing Service again and run the sample app.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group.

From the Azure portal menu or Home page, select Resource groups, and on the Resource groups page, select myResourceGroup.

On the myResourceGroup page, make sure that the listed resources are the ones you want to delete.

Select Delete, type myResourceGroup in the text box, and then select Delete.

Next steps

In this tutorial, you've used Azure Cosmos DB to share anchor identifiers across devices. To learn more about how to use Azure Spatial Anchors in a new Unity HoloLens app, continue to the next tutorial.