1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

この記事誰得? 私しか得しないニッチな技術で記事投稿!
Qiita Engineer Festa20242024年7月17日まで開催中!

【Azure CosmosDB】存在しないデータをSELECTするだけで例外になる

Last updated at Posted at 2024-07-15

解決方法わかりません。

CosmosDBからID指定でデータを取得する際は、Container.ReadItemAsyncを使うと楽です。

use Microsoft.Azure.Cosmos;

CosmosClient cosmosClient = new("エンドポイント");
Database database = cosmosClient.GetDatabase("DB名");
Container container = database.GetContainer("テーブル名");
ItemResponse<DummyModel> itemResponse = await container.ReadItemAsync<DummyModel>("ID", new PartitionKey("partitionKey"));

ところが最後のReadItemAsync()で、存在しないIDを指定するとCosmosExceptionが発生します。
なんで。

さらにCosmosDB側にも404のステータスコードが発生します。
なんで。

普通に、存在しなかったらnullとか空配列を返してくれるだけでいいんだけど。
せめてItemRequestOptionsとかで対応できないものでしょうか。
こんなクッソどうでもいいログがいちいちLog Analyticsとかにまで流れて無駄なんで止めたいんですが。

こんなおかしな挙動何も言われないわけがなく既にIssueになっているのですが、しかしこれ対応なんてしねえよでFAです。
どうにかするにはStreaming APIを使え、っことらしいのですが、このStreaming API全然情報が出てこないのでよくわからない。
どうしてFromStreamとかいちいち自力で実装しないといけないんですか?

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?