Reputation: 3685
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
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:
Thanks!
Upvotes: 1