Etablera standarddataflöde (manuell) på en Azure Cosmos DB-container – API för NoSQL

GÄLLER FÖR: NoSQL

Den här artikeln beskriver hur du etablerar standarddataflöde (manuellt) på en container i Azure Cosmos DB för NoSQL. Du kan etablera dataflöde på en enda container eller etablera dataflöde i en databas och dela det mellan containrarna i databasen. Du kan etablera dataflöde i en container med hjälp av Azure-portalen, Azure CLI eller Azure Cosmos DB SDK:er.

Om du använder ett annat API kan du läsa api för MongoDB, API för Cassandra, API för Gremlin-artiklar för att etablera dataflödet.

Azure Portal

  1. Logga in på Azure-portalen.

  2. Skapa ett nytt Azure Cosmos DB-konto eller välj ett befintligt Azure Cosmos DB-konto.

  3. Öppna fönstret Datautforskaren och välj Ny container. Ange därefter följande information:

    • Ange huruvida du skapar en ny databas eller använder en befintlig.
    • Ange ett container-ID.
    • Ange ett partitionsnyckelvärde (till exempel /ItemID).
    • Välj Autoskalning eller Manuellt dataflöde och ange det nödvändiga dataflödet för containrar (till exempel 1 000 RU/s). Ange ett dataflöde som du vill etablera (till exempel 1 000 RU:er).
    • Välj OK.

    Screenshot of Data Explorer, with New Collection highlighted

Azure CLI eller PowerShell

Information om hur du skapar en container med dedikerat dataflöde finns i

.NET SDK

Kommentar

Använd Azure Cosmos DB SDK:er för API för NoSQL för att etablera dataflöde för alla Azure Cosmos DB-API:er, förutom Cassandra och API för MongoDB.

// Create a container with a partition key and provision throughput of 400 RU/s
DocumentCollection myCollection = new DocumentCollection();
myCollection.Id = "myContainerName";
myCollection.PartitionKey.Paths.Add("/myPartitionKey");

await client.CreateDocumentCollectionAsync(
    UriFactory.CreateDatabaseUri("myDatabaseName"),
    myCollection,
    new RequestOptions { OfferThroughput = 400 });

JavaScript SDK

// Create a new Client
const client = new CosmosClient({ endpoint, key });

// Create a database
const { database } = await client.databases.createIfNotExists({ id: "databaseId" });

// Create a container with the specified throughput
const { resource } = await database.containers.createIfNotExists({
id: "containerId",
throughput: 1000
});

// To update an existing container or databases throughput, you need to user the offers API
// Get all the offers
const { resources: offers } = await client.offers.readAll().fetchAll();

// Find the offer associated with your container or the database
const offer = offers.find((_offer) => _offer.offerResourceId === resource._rid);

// Change the throughput value
offer.content.offerThroughput = 2000;

// Replace the offer.
await client.offer(offer.id).replace(offer);

Nästa steg

I följande artiklar kan du lära dig hur du etablerar dataflöde i Azure Cosmos DB: