我正在开发一个用于大数据规模的系统。目前,我正在测试少于 300k 个文档的集合存储过程。
我正在遵循这个例子:DocumentDB 服务器端编程:存储过程、数据库触发器和 UDF
到目前为止,"createDocument"和"replaceDocument"工作正常。但是无论我尝试多少种方法,查询文档都根本不起作用。我试图在很多地方放置抛出异常,但在回调中抛出异常根本没有被击中。
有没有人在存储过程中成功使用 queryDocuments()?
function MoveTree(nodeJson, targetParentNodeJson) {
var node = JSON.parse(nodeJson);
var targetParentNode = JSON.parse(targetParentNodeJson);
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var count = 0;
//<==Tried put throw exception here and it is hit
var node;
var IsAccept = collection.queryDocuments(
collection.getSelfLink(),
'SELECT * FROM Nodes p where p.id = "' + nodeId + '"',
function (err, documents, responseOptions) {
//<==Tried put throw exception here but it is not hit
if (err) throw new Error(err);
if (!documents || documents.length != 1) throw new Error("Unable to find node.");
node = documents[0];
//<==Tried put throw exception here but it is not hit
});
//<==Tried put throw exception here and it is hit
//...}
带有注释的代码屏幕截图
正如拉里所提到的,问题是你没有设置nodeId
变量......这会导致运行时出现以下错误消息:
Encountered exception while executing Javascript. Exception = ReferenceError: 'nodeId' is undefined