-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathustlink.txt
94 lines (63 loc) · 2.51 KB
/
ustlink.txt
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
VS Code : https://code.visualstudio.com/docs/?dv=win
https://dotnet.microsoft.com/en-us/download/dotnet/7.0
Downlod sdk & runtime in system
clone git
https://github.com/microsoftlearning/dp-420-cosmos-db-dev
put below code in script.cs
using System;
using System.Linq;
using Microsoft.Azure.Cosmos;
string endpoint = "<cosmos-endpoint>";
string key = "<cosmos-key>";
CosmosClient client = new (endpoint, key);
AccountProperties account = await client.ReadAccountAsync();
Console.WriteLine($"Account Name:\t{account.Id}");
Console.WriteLine($"Primary Region:\t{account.WritableRegions.FirstOrDefault()?.Name}");
------------------------------------------------------------------------------------------------
For CRUD
using System;
using Microsoft.Azure.Cosmos;
string endpoint = "https://madhangicosmosdb.documents.azure.com:443/";
string key = "QCh8V9HVHkDiePiYVRrgezRlK04yFb2N6eX3yLmEAO0jr9m3S23yZi98ProAmwLykbxXxLRzAnbLACDbfS3KFA==";
CosmosClient client = new CosmosClient(endpoint, key);
Database database = await client.CreateDatabaseIfNotExistsAsync("SampleDB");
Container container = await database.CreateContainerIfNotExistsAsync("products", "/categoryId", 400);
Product saddle = new()
{
id = "706cd7c6-db8b-41f9-aea2-0e0c7e8eb009",
categoryId = "9603ca6c-9e28-4a02-9194-51cdb7fea816",
name = "Road Saddle",
price = 45.99d,
tags = new string[]
{
"tan",
"new",
"crisp"
}
};
await container.CreateItemAsync<Product>(saddle);
--------------------------------------------------------------------
Paginate sql query
using System;
using Microsoft.Azure.Cosmos;
string endpoint = "https://madhangicosmosdb.documents.azure.com:443/";
string key = "QCh8V9HVHkDiePiYVRrgezRlK04yFb2N6eX3yLmEAO0jr9m3S23yZi98ProAmwLykbxXxLRzAnbLACDbfS3KFA==";
CosmosClient client = new CosmosClient(endpoint, key);
Database database = await client.CreateDatabaseIfNotExistsAsync("SampleDB");
Container container = await database.CreateContainerIfNotExistsAsync("products", "/categoryId");
using FeedIterator<Product> feed = container.GetItemQueryIterator<Product>(
queryText: "SELECT * FROM products"
);
// Iterate query result pages
while (feed.HasMoreResults)
{
FeedResponse<Product> response = await feed.ReadNextAsync();
// Iterate query results
foreach (Product item in response)
{
Console.WriteLine($"Found item:\t{item.name}");
}
}
open terminal run below comman
dotnet add package Microsoft.Azure.Cosmos --version 3.22.1
dotnet run