2017-12-20 2 views
1

SQL/DocumentDBインターフェイスを使用しているCosmosDBインスタンスがあります。私は.NET SDK経由でアクセスしています。ExecuteStoredProcedureAsyncから100以上のドキュメントを取得する

私はExecuteStoredProcedureAsyncで呼び出すストアドプロシージャを持っています。しかし、最大100件の文書しか戻すことができません。私はこれがデフォルトオプションであることを知っています。それを変更することはできますか?

ExecuteStoredProcedureAsyncのオプションのパラメータはRequestOptionsオブジェクトです。 RequestOptionsにはMaxItemCountまたは継続トークンのプロパティはありません。

答えて

1

返却するレコードの量を調整するには、SP自体を変更する必要があります。ここでは/ここSP-

function storedProcedure(continuationToken, take){ 

    var filterQuery = "SELECT * FROM ..."; 
    var accept = __.queryDocuments(__.getSelfLink(), filterQuery, {pageSize: take, continuation: continuationToken}, 

    function (err, documents, responseOptions) { 
     if (err) throw new Error("Error" + err.message); 

     __.response.setBody({ 
      result: documents, 
      continuation: responseOptions.continuation 
     }); 
    }); 
} 

のロジックを取る実装スキップして完全な例は、対応するC#コードです:

 string continuationToken = null; 
     int pageSize = 500; 

     do 
     { 
      var r = await client.ExecuteStoredProcedureAsync<dynamic>(
       UriFactory.CreateStoredProcedureUri(DatabaseId, CollectionId, "SP_NAME"), 
       new RequestOptions { PartitionKey = new PartitionKey("...") }, 
       continuationToken, pageSize); 

      var documents = r.Response.result; 
      // processing documents ... 
      // 'dynamic' could be easily substituted with a class that will cater your needs 

      continuationToken = r.Response.continuation; 
     } 
     while (!string.IsNullOrEmpty(continuationToken));  

あなたが見ることができるように、数を制御するパラメータがあります返信するレコード - ページサイズご存知のように、pageSizeはデフォルトで100です。一度にすべてを返す必要がある場合は、-1を指定します。

0

RequestOptionsにはMaxItemCountまたは 継続トークンのプロパティがありません。

MaxItemCountは、Feedoptionsのパラメータです。

ExecuteStoredProcedureAsyncメソッドは、返されるデータエントリを制限しません。キーは、ストアドプロシージャのクエリ操作で返すエントリの最大数を設定します。

として以下のサンプルストアドプロシージャのコードを参照してください:

function sample(prefix) { 
    var collection = getContext().getCollection(); 



    var isAccepted = collection.queryDocuments(
     collection.getSelfLink(), 
     'SELECT * FROM root r', 
     { pageSize: 1000 }, 
    function (err, feed, options) { 
     if (err) throw err; 
     if (!feed || !feed.length) { 
      var response = getContext().getResponse(); 
      response.setBody('no docs found'); 
     } 
     else { 
      var response = getContext().getResponse(); 
      var body = ""; 
      for(var i=0 ; i<feed.length;i++){ 
       body +="{"+feed[i].id+"}"; 
      } 
      response.setBody(JSON.stringify(body)); 
     } 
    }); 

    if (!isAccepted) throw new Error('The query was not accepted by the server.'); 
} 

結果:あなたは店の手続きをテストするためにスクリーンショットにはどのようなツールを使用している

enter image description here

+0

を? – epotter

+0

@epotterポータルのコスモスアカウントのスクリプトエクスプローラ。 –

+0

@epotter今すぐ更新がありますか? –

関連する問題