DocumentDB存储过程queryDocument不返回任何内容 [英] DocumentDB stored procedure queryDocument returns nothing
问题描述
我修改了原始存储的proc以显示该问题.我莫名其妙地努力从集合中取回文档.现在,我只是尝试通过id获取文档,但这样做仍然失败.我总是收到"True error"消息,表示没有文档.但是,当我在查询窗口中运行查询时,文档返回没有任何问题.我真的不知道问题可能是什么.下面是我的代码.任何帮助表示赞赏.
I modify my original stored proc to show the issue. I somehow struggle to get the document(s) back from the collection. Now, I just try to get the document by id, and it still fails to do so. I always get the "True error" message back which means no document. However, when I run the query in the query window, the document is returned without any issue. I really have no idea what the issue can be. Below is my code. Any help appreciated.
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.");
}
}
推荐答案
似乎您的代码中存在一些语法错误.当使用您提到的代码时,我们收到了以下错误信息,我们可以从Azure门户测试存储的proc.
It seems that there is some syntaxError in your code. We could test the stored proc from the Azure portal, when use the code you mentioned I got following error info.
请尝试使用以下代码再次进行测试,它对我有效.
Please have a try use to the following code to test again, it works on my side.
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查询中是区分大小写.
Note: field name it is case sensitive in the sql query in the documentdb.
这篇关于DocumentDB存储过程queryDocument不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!