我正在使用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):
,但没有任何实际执行。
这完美地工作,谢谢! document_client非常庞大,我没有看到其他方法隐藏在底部。 –