2016-07-06 52 views
0

我正在使用Tornado和pydocumentDB在Azure上運行存儲應用程序。我也有一個存儲過程:使用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);    
     }); 
    } 

我想要做的就是增加我user_ids文檔的counter屬性生成一個新的用戶每次和他們的文檔添加到集合。是否可以調用該Sproc,更新計數器,然後查詢文檔中的新計數器,然後使用該新計數器作爲新用戶的ID? GitHub上的documentDB SDK顯示了幾個方法,如QueryStoredProcedures(self, collection_link, query, options=None): ReadStoredProcedures(self, collection_link, options=None):,但沒有任何實際執行。

回答

相關問題