我有以下存储过程,该过程被编写用于基于延续令牌的机制,用于从documentDB集合中获取文档:
这是正确的方法吗?
function getOrdersByBranchNumber(branchNumber){
var context = getContext();
var collection = context.getCollection();
var link = collection.getSelfLink();
var response = context.getResponse();
var nodesBatch = [];
var continuationToken = true;
var responseSize = 0;
//validate inputs
if(!branchNumber || (typeof branchNumber != "string")){
return errorResponse(400, (!branchNumber) ? "branchNumber is Undefined":"String type is expected for branchNumber.");
}
var querySelect = "SELECT * from orders o WHERE o.branchNbr = '"+branchNumber+"' ";
var query = { query: querySelect};
getNodes(continuationToken);
function getNodes(continuationToken) {
var requestOptions = {
continuation: continuationToken,
pageSize: 90
};
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
query,
requestOptions,
function (err, feed, options) {
var queryPageSize = JSON.stringify(feed).length;
// DocumentDB has a response size limit of 1 MB.
if (responseSize + queryPageSize < 1024 * 1024) {
// Append query results to nodesBatch.
nodesBatch = nodesBatch.concat(feed);
// 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.
var feedData=JSON.stringify(nodesBatch);
getContext().getResponse().setBody(feedData);
}
} else {
// If the response size limit reached; run the script again with the lastContinuationToken as a script parameter.
var feedData=JSON.stringify(nodesBatch);
getContext().getResponse().setBody(feedData);
}
});
if (!isAccepted){
return errorResponse(400, "The query was not accepted by the server.");
}
}
function errorResponse(code,message){
var errorObj = {};
errorObj.code = code;
errorObj.message = message;
errorObj.date = getDateTime();
return response.setBody(errorObj);
}
function getDateTime(){
var currentdate = new Date();
var dateTime = currentdate.getFullYear() + "-" +(currentdate.getMonth()+1)+ "-" + currentdate.getDate()+ " " +currentdate.getHours()+":"+currentdate.getMinutes() +":"+currentdate.getSeconds();
return dateTime;
}
}
但是我在保存并执行存储过程后看到下面提到的错误。
知道查询中有什么问题吗?
Encountered exception while executing Javascript. Exception = Error: Invalid
arguments for query.
Stack trace: Error: Invalid arguments for query.
at queryDocuments (getOrdersByBranchNumber.js:614:17)
at getNodes (getOrdersByBranchNumber.js:27:5)
at getOrdersByBranchNumber (getOrdersByBranchNumber.js:19:1)
at __docDbMain (getOrdersByBranchNumber.js:78:5)
at Global code (getOrdersByBranchNumber.js:1:2)
答案 0 :(得分:0)
尝试删除查询选项上的继续项。指定无效的错误时,我会收到此错误。