私はTornadoとpydocumentDBを使用してAzureでストレージアプリケーションを実行しています。私は何をしようとしていることは私のuser_ids文書のcounter
プロパティに新しいユーザーが生成され、その文書をコレクションに追加されるたびに増加しているdocumentDB SDK for Pythonを使用してストアドプロシージャを実行することはできますか?
function userIDSproc() {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
"SELECT * FROM root r WHERE r.id='user_ids_counter'",
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
else tryUpdate(feed[0])
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
function tryUpdate(document){
document.counter += 1;
getContext().getResponse().setBody(document['counter']);
var isAccepted = collection.replaceDocument(document._self, document, function (err, document, options) {
if (err) throw err;
// If we have successfully updated the document - return it in the response body.
getContext().getResponse().setBody(document);
});
}
:私はまた、ストアドプロシージャを持っています。そのSprocを呼び出してカウンタを更新し、次に新しいカウンタをドキュメントに照会し、その新しいカウンタを新しいユーザのIDとして使用することは可能ですか? GitHubのdocumentDB SDKには、QueryStoredProcedures(self, collection_link, query, options=None):
とReadStoredProcedures(self, collection_link, options=None):
のような2つのメソッドがありますが、実際には何も実行されません。
は、これは完全に働いた、ありがとう! document_clientはかなり巨大で、私はそこの底に隠れている他の方法を見ていませんでした。 –