2017-05-31 65 views
0

我是Azure DocumentDB的新手,在執行非常基本的存儲過程時遇到一些意外的行爲。存儲過程(如下所示)返回「找不到文檔」,但SELECT語句查詢的集合中填充了許多文檔。進一步阻礙我的是,在查詢瀏覽器中運行相同的SELECT語句會導致按預期返回單個文檔。我在這裏錯過了一些真正的基礎嗎?Azure DocumentDB存儲過程不會返回任何內容

function simple() { 
    var collection = getContext().getCollection(); 

    // Query documents and take 1st item. 
    var isAccepted = collection.queryDocuments(
     collection.getSelfLink(), 
     'SELECT TOP 1 * FROM MyCollection c', 
     function (err, feed, options) { 
      if (err) throw err; 

      // Check the feed and if it's empty, set the body to 'no docs found', 
      // Otherwise just take 1st element from the feed. 
      if (!feed || !feed.length) getContext().getResponse().setBody("no docs found"); 
      else getContext().getResponse().setBody(JSON.stringify(feed[0])); 
     }); 

    if (!isAccepted) throw new Error("The query wasn't accepted by the server. Try again/use continuation token between API and script."); 
} 
+0

只是好奇:你有一個分區集合,或單分區集合? –

+0

是的,集合是分區的。 –

回答

0



該sproc看起來不錯。我用一些文檔在一個集合上運行了這個,並且如預期的那樣,sproc返回了1個文檔,所以我不能重複這個。以下是我建議:

  1. 嘗試在一個小集合
  2. 更改存儲過程的運行,這樣的情況下,飼料是空的,以「沒有發現文件」,返回options.continuation,看看是否延續標記爲空沿或不。這可能是查詢被搶先了,儘管這是不太可能的。

謝謝!

相關問題