我一直在阅读有限的文档,而且从我所看到的情况来看,此查询应该有效。
// SAMPLE STORED PROCEDURE
function sample() {
var prefix = "";
var collection = getContext().getCollection();
var data = collection.readDocuments(collection.getSelfLink());
console.log(data);
console.log(JSON.stringify(data));
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT * FROM root r',
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) {
var response = getContext().getResponse();
response.setBody('no docs found');
}
else {
var response = getContext().getResponse();
var body = { prefix: prefix, feed: feed[0] };
response.setBody(JSON.stringify(body));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
毕竟,这只是门户生成的示例查询。唯一的问题是它不会返回任何结果。
/EmailTypeId
5
(这是所有当前记录的分区值)collection.readDocuments
的调用,该调用应返回所有文档,但只返回值true
以下是集合中其中一个doc模式的示例屏幕截图
以下是提供分区值的输入表单
我创建了一个新的集合作为控件。此集合没有分区键,似乎同一查询返回该集合中的结果。因此问题必须出在我提供的第二个屏幕截图中。也许我错误地提供了分区密钥。
答案 0 :(得分:0)
我认为您需要限制您的响应大小,因为cosmo存在限制。我在我的sproc中添加了类似的内容来缓解这个问题:
if (responseSize + queryPageSize < 1024 * 1024) {
// Append query results to nodesBatch.
nodesBatch = nodesBatch.concat(documentsRead);
// Keep track of the response size.
responseSize += queryPageSize;
if (responseOptions.continuation) {
// If there is a continuation token... Run the query again to get the next page of results
lastContinuationToken = responseOptions.continuation;
getNodes(responseOptions.continuation);
} else {
// If there is no continutation token, we are done. Return the response.
response.setBody({
"message": "Query completed succesfully.",
"queryResponse": nodesBatch
});
}
} else {
// If the response size limit reached; run the script again with the lastContinuationToken as a script parameter.
response.setBody({
"message": "Response size limit reached.",
"lastContinuationToken": lastContinuationToken,
"queryResponse": nodesBatch
});
}
});
让我知道这对你有用。
另外,请检查您的收藏名称并使用该名称而不是root