-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
34 lines (23 loc) · 1.14 KB
/
Program.cs
File metadata and controls
34 lines (23 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.AddUserSecrets<Program>().Build();
var cosmosClient = new CosmosClient(configuration.GetConnectionString("CosmosDb"));
var container = cosmosClient.GetContainer(databaseId: "ToDoList", "Searches");
// document about 100KB
var item = new Item(Guid.NewGuid().ToString(), new string('a', 102_400));
_ = await container.CreateItemAsync(item);
var pointReadResponse = await container.ReadItemAsync<Item>(item.id, new PartitionKey(item.id));
Console.WriteLine($"Point read: {pointReadResponse.RequestCharge} RUs");
var query = new QueryDefinition("SELECT * FROM c WHERE c.id = @id")
.WithParameter("@id", item.id);
using var queryResults = container.GetItemQueryIterator<Item>(query);
while (queryResults.HasMoreResults)
{
var response = await queryResults.ReadNextAsync();
Console.WriteLine($"Query by partition key: {response.RequestCharge} RUs");
Console.WriteLine($"Returned items: {response.Count}");
}
record struct Item(string id, string padding);