魅力:
私は、SQL APIとAzureのコスモスDBに取り組んでいます。私はからのAzure SDKを使用しています:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>2.4.7</version>
</dependency>
私はのリスト持っているIDを、そして私が持つすべての文書を見つけるしたいと思いIDS私のリストからを。私は次のように私は「IN」クエリを定義したAzureのSDK SqlQuerySpecを、使用していることを達成するために:
List<String> ids = Lists.newArrayList("1");
SqlQuerySpec spec = new SqlQuerySpec(
"SELECT * FROM MyLog c WHERE c.id IN (@ids)",
new SqlParameterCollection(new SqlParameter("@ids", ids)));
FeedResponse<Document> documentFeedResponse = documentClient.queryDocuments(collectionLink, spec, queryOptions);
List<Document> documents = documentFeedResponse.getQueryIterable().toList();
私のデータベースに私はID = 1の文書を持っているが、残念ながら「ドキュメント」リストは、空です。ただ、ダブルチェックに私は、ポータルでクエリを実行しようとしています。
SELECT * FROM Cどこc.id IN( "1")
それは、正しくデータを返します。だから私は、私が間違ってやっているかわからないです。誰もがすでに与えられたIDを持つ文書のリストを取得するためにSqlQuerySpecを作成していますか?
ジェイ功:
実際には、IN
同じように使用されwhere c.id IN ("1")
、paramが配列ではありません。
あなたは使用することができArray_Contains
、あなたの必要性を実装します:
List<String> ids = new ArrayList<String>();
ids.add("1");
ids.add("2");
SqlQuerySpec spec = new SqlQuerySpec(
"SELECT * FROM c WHERE array_contains(@ids, c.id )",
new SqlParameterCollection(new SqlParameter("@ids", ids)));
FeedResponse<Document> documentFeedResponse = documentClient.queryDocuments(collectionLink, spec, feedOptions);
List<Document> documents = documentFeedResponse.getQueryIterable().toList();
出力: