JTW
JTW

Reputation: 3685

Azure DocumentDB stored procedure returns nothing

I'm new to Azure DocumentDB and encountering some unexpected behavior when executing a very basic stored procedure. The stored procedure (shown below) is returning "no docs found", but the collection that the SELECT statement is querying from is populated with many documents. Baffling me further is the fact that running the same SELECT statement in the Query Explorer results in a single document being returned as expected. Am I missing something really fundamental here?

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.");
}

Upvotes: 2

Views: 497

Answers (1)

Michael Koltachev
Michael Koltachev

Reputation: 509



The sproc looks fine. I ran this on a collection with a couple of docs and the sproc returns 1 doc as expected, so I can't repro this. Here's what I recommend:

  1. Try running on a small collection
  2. Change the sproc so that in case feed is empty, along with "no docs found", return options.continuation and see if continuation token is empty or not. It could be that the query was pre-empted although this is very unlikely.

Thanks!

Upvotes: 1

Related Questions