azureazure-cosmosdbregionazureportalregions

CosmosDB How to read replicated data


I'm using CosmosDB and replicating the data globally. (One Write region; multiple Read regions). Using the Portal's Data Explorer, I can see the data in the Write region. How can I query data in the Read regions? I'd like some assurance that it's actually working, and haven't been able to find any info or even an URL for the replicated DBs.

Note: I'm writing to the DB via the CosmosDB "Create or update document" Connector in a Logic App. Given that this is a codeless environment, I'd prefer to validate the replication without having to write code.


Solution

  • How can I query data in the Read regions?

    If code is possible, we could access from every region your application is deployed, configure the corresponding preferred regions list for each region via one of the supported SDKs

    The following is the demo code for Azure SQL API CosmosDB. For more information, please refer to this tutorial.

    ConnectionPolicy usConnectionPolicy = new ConnectionPolicy 
    { 
        ConnectionMode = ConnectionMode.Direct,
        ConnectionProtocol = Protocol.Tcp
    };
    
    usConnectionPolicy.PreferredLocations.Add(LocationNames.WestUS); //first preference
    usConnectionPolicy.PreferredLocations.Add(LocationNames.NorthEurope); //second preference
    
    DocumentClient usClient = new DocumentClient(
        new Uri("https://contosodb.documents.azure.com"),
        "<Fill your Cosmos DB account's AuthorizationKey>",
        usConnectionPolicy);
    

    Update:

    We can enable Automatic Failover from Azure portal. Then we could drag and drop the read regions items to recorder the failover priorties.

    enter image description here