Azure Cosmos DB Core (SQL)

  • 首先要有cosmos db的account
  • 然后才可以生成cosmos db,默认throughput是4000(而且4000是最小值),自动调整从10%(即400 RU/s)开始。
    Your container throughput will automatically scale from 400 RU/s (10% of max RU/s) - 4000 RU/s based on usage.
  • 然后生成container,相当于传统数据库表的表,container共享db的throughput。

代码生成cosmos db.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

namespace myApp
{
    public class Program
    {
        private static readonly string _endpointUri = "YOUR_URI";
        private static readonly string _primaryKey = "YOUR_KEY";
        public static async Task Main(string[] args)
        {         
            using (CosmosClient client = new CosmosClient(_endpointUri, _primaryKey))
            {        
                DatabaseResponse databaseResponse = await client.CreateDatabaseIfNotExistsAsync("Products");
                Database targetDatabase = databaseResponse.Database;
                await Console.Out.WriteLineAsync($"Database Id:\t{targetDatabase.Id}");
                IndexingPolicy indexingPolicy = new IndexingPolicy
                {
                    IndexingMode = IndexingMode.Consistent,
                    Automatic = true,
                    IncludedPaths =
                    {
                        new IncludedPath
                        {
                            Path = "/*"
                        }
                    }
                };
                var containerProperties = new ContainerProperties("Clothing", "/productId")
                {
                    IndexingPolicy = indexingPolicy
                };
                var containerResponse = await targetDatabase.CreateContainerIfNotExistsAsync(containerProperties, 10000);
                var customContainer = containerResponse.Container;
                await Console.Out.WriteLineAsync($"Custom Container Id:\t{customContainer.Id}");
            }
        }
    }
}
--------------------------- 知道的更多,不知道的也更多 ---------------------------
原文地址:https://www.cnblogs.com/mryux/p/15279234.html