This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Which block of code should be used to create a client to connect to the Azure Cosmos DB account with only a connection string?
string connectionString = "<cosmos-connection-string>"; using CosmosClient client = new(connectionString);
string connectionString = "<cosmos-connection-string>"; using CosmosClient client = new(connectionString, "");
string connectionString = "<cosmos-connection-string>"; using CosmosClient client = new();
Consider a new Azure Cosmos DB account without any resources. Which block of code creates the first server-side resource that is required to store a set of containers?
using CosmosClient client = new( connectionString: cosmosConnectionString );
Container container = await database.CreateContainerIfNotExistsAsync( "products", partitionKeyPath: "/department", throughput: 400 );
Database database = await client.CreateDatabaseIfNotExistsAsync( "adventureworks" );
An item already exists in the Azure Cosmos DB for NoSQL account with a unique identifier of 04b3038c-b966-4a86-a1f3-5d1fa5c2a47c. Which of the following blocks of code replace the existing item in the container with a newly created item without running the risk of creating an entirely new item.
04b3038c-b966-4a86-a1f3-5d1fa5c2a47c
Item item = new("04b3038c-b966-4a86-a1f3-5d1fa5c2a47c", "item-category", "item-name", 0, true); container.UpsertItemAsync(item);
Item item = new("04b3038c-b966-4a86-a1f3-5d1fa5c2a47c", "item-category", "item-name", 0, true); container.ReplaceItemAsync("04b3038c-b966-4a86-a1f3-5d1fa5c2a47c", item);
Item item = new("04b3038c-b966-4a86-a1f3-5d1fa5c2a47c", "item-category", "item-name", 0, true); container.CreateItemAsync(item);
Here's an Azure Cosmos DB for NoSQL query: SELECT * FROM container c WHERE c.partitionKey == 'some-category' ORDER BY c.id. What is the language-integrated query (LINQ) equivalent of this query?
SELECT * FROM container c WHERE c.partitionKey == 'some-category' ORDER BY c.id
using FeedIterator<Product> feed = container.GetItemLinqQueryable<Item>() .OrderBy(i => i.partitionKey) .ToFeedIterator();
using FeedIterator<Product> feed = container.GetItemLinqQueryable<Item>() .Where(i => i.id == "some-category") .ToFeedIterator();
using FeedIterator<Product> feed = container.GetItemLinqQueryable<Item>() .Where(i => i.partitionKey == "some-category") .OrderBy(i => i.id) .ToFeedIterator();
You must answer all questions before checking your work.
Continue
Was this page helpful?