我修改原始存储过程以显示问题。我在某种程度上很难从收集中取回文件。现在,我只是尝试通过id获取文档,但仍然没有这样做。我总是得到"真正的错误"消息返回,这意味着没有文件。但是,当我在查询窗口中运行查询时,将返回文档而不会出现任何问题。我真的不知道问题是什么。以下是我的代码。任何帮助表示赞赏。
function removeDisconnectedUserFromAllRooms(connectionID){
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
var nodesBatch = [];
if (!connectionID) throw new Error("The id is undefined or null.");
var query = {query: "select * from rooms where rooms.RoomID = @connectionID", parameters: [{name: "@connectionID", value: connectionID}]};
var isAccepted = collection.queryDocuments(collectionLink, query, function (err, documents, options) {
if (err) throw err;
if (documents.length > 0) {
response.setBody(documents.length);
}
else if (options.continuation){
response.setBody("has token");
}
else {
// Else a document with the given id does not exist..
response.setBody("true error");
}
});
}
if(!isAccepted) {
throw new Error("The stored procedure timed out.");
}
}
答案 0 :(得分:0)
您的代码中似乎存在一些syntaxError。我们可以测试来自Azure门户的存储过程,当你使用你提到的代码时我得到了错误信息。
请尝试使用以下代码再次测试,它适用于我。
function removeDisconnectedUserFromAllRooms(connectionID){
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
var nodesBatch = [];
if (!id) throw new Error("The id is undefined or null.");
var query = {query: "select * from rooms where rooms.RoomId= @connectionID", parameters: [{name: "@connectionID", value: connectionID}]};
var isAccepted = collection.queryDocuments(collectionLink, query, function (err, documents, options) {
if (err) throw err;
if (documents.length > 0) {
response.setBody(documents.length);
}
else if (options.continuation){
response.setBody("has token");
}
else {
// Else a document with the given id does not exist..
response.setBody("true error");
}
});
if(!isAccepted) {
throw new Error("The stored procedure timed out.");
}
}
注意:在documentdb的sql查询中,字段名称是区分大小写。