[英]How can I only pass in Partition Key when using ReadItemAsync? - Cosmos DB
我正在嘗試僅針對分區鍵運行ReadItemAsync
。 Key 是用戶將要搜索的 7 位數字。 Partition Key 存在於同一個容器中,但存在多次,因為我們根據月份拆分數據,因此,每個 Partition Key 將存在 12 次,但 ID 會發生變化。
代碼字面意思是: var feedIterator = await Container.ReadItemAsync<JObject>("id", new PartitionKey(partitionKey));
數據庫架構:
ID | /分區鍵 |
---|---|
abcd1234-1111-2222-9f4a-8fea7044faf4 | 1200001 |
abcd1234-1111-2222-9d1e-49096cc32731 | 1200001 |
abcd1234-1111-2222-a6ab-f249eed57eb7 | 1200001 |
abcd1234-1111-2222-ba31-422ccccd1aef | 1200001 |
abcd1234-1111-2222-ba14-d6fb786dab3e | 1200001 |
abcd1234-1111-2222-89a0-c5434c3192d0 | 1200001 |
abcd1234-1111-2222-b8fb-9d5fdd0ab811 | 1200001 |
干杯,山姆
如果您知道要讀取的文檔的 ID 和分區鍵值,則可以使用container.ReadManyItemsAsync
:
List<(string, PartitionKey)> itemList = new List<(string, PartitionKey)>
{
("abcd1234-1111-2222-9f4a-8fea7044faf4", new PartitionKey("1200001")),
("abcd1234-1111-2222-9d1e-49096cc32731", new PartitionKey("1200001")),
("abcd1234-1111-2222-a6ab-f249eed57eb7", new PartitionKey("1200001")),
...
;
Console.WriteLine("\nItems in read list:" + itemList.Count);
FeedResponse<SalesOrder> feedResponse = await container.ReadManyItemsAsync<SalesOrder>(
如果您不知道 ID,只知道分區鍵值,則可以進行查詢:
using (FeedIterator<MyItem> feedIterator = container.GetItemQueryIterator<MyItem>(
"SELECT * FROM c",
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("1200001")}))
{
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.