2016-07-06 3 views
0

私は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つのメソッドがありますが、実際には何も実行されません。

答えて

0

DocumentDB Python SDKの場合は、ExecuteStoredProcedure(self, sproc_link, params, options=None)を呼び出すことができます。

現在のSDKのユニットテストでは簡単な例を見つけることができます。

https://github.com/Azure/azure-documentdb-python/blob/e605e7ca7b1ddd2454f1014f536a0fded9e6f234/test/crud_tests.py#L3408-L3409

+0

は、これは完全に働いた、ありがとう! document_clientはかなり巨大で、私はそこの底に隠れている他の方法を見ていませんでした。 –

関連する問題