gpt4 book ai didi

azure-cosmosdb - CosmosDB 存储过程返回错误 "Encountered exception while executing Javascript. Exception = Error: Invalid arguments for query"

转载 作者:行者123 更新时间:2023-12-01 12:17:37 25 4
gpt4 key购买 nike

我有以下存储过程,它是为基于延续 token 的机制而编写的,用于从 documentDB 集合中获取文档:

  1. 我遇到查询异常。
  2. 我正在尝试使用延续 token 获取所有文档。

这是正确的方法吗?

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)

最佳答案

尝试删除查询选项中的延续项。当我指定了一个无效的时,我得到了这个错误。

关于azure-cosmosdb - CosmosDB 存储过程返回错误 "Encountered exception while executing Javascript. Exception = Error: Invalid arguments for query",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45802786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com