1

Google Datastoreでページネーションを実行する際に問題が発生しています。私は制限なしで数百の結果を持っているクエリを持っています。Googleデータストアでのノードのページ設定

var query = datastore.createQuery('ResultsKind').filter('name', 'bobby').limit(5).autoPaginate(false); 

は、私は、このクエリを実行します。ユーザーはより多くの彼らは、私は、クエリを作成するには、次の5

次のドキュメントを取得します望んでいる場合、私は、5を取得し、ユーザーに戻ってそれらを送りたいです最初の5件の結果を得るために:

datastore.runQuery(query, callback); 

する。これは、コールバック関数です:

function callback(err, entities, nextQuery, apiResponse) { 
    if (err) { 
     // An error occurred while running the query. 
     console.log('err ' + err); 
     return; 
    } 

    if (nextQuery) { 
     console.log('res = ' + entities); 
     datastore.runQuery(nextQuery, callback); 
    } else { 
     // No more results exist. 
     console.log('no more results'); 
     return; 
    } 
}; 

問題はres =が無限に印刷され、結果がコンソールに表示されません。私が間違っていることがわかりません。私は何が起こりたいのですか?

1) I create the initial query. 
2) I run the query. 
3) I get the first 5 results. 
4) I pass these results + the nextquery object to the user. 
5) If the user wants more results the pass me back the nextQuery and I run this query and get the next 5 results and so on. 

この文書は、http://googlecloudplatform.github.io/gcloud-node/#/docs/v0.30.2/datastore/query?method=autoPaginateです。

この単純なページングをどのように達成できますか?あなたのコールバックの中に、あなたはconsole.log後に直接クエリを再実行しているから

答えて

1

if (nextQuery) { 
    console.log('res = ' + entities); 
    datastore.runQuery(nextQuery, callback); // <-- Here 
} 

これは、本質的にautoPaginate(true)が行うのと同じことをやっています。その代わりに、その行を削除してnextQueryをキャッシュし、削除した行と同じ行を実行して、ユーザーが要求したときに次のバッチ結果を取得する必要があります。

+0

ありがとうございます! – user2924127

関連する問題