简体   繁体   English

ArangoDB:处理遍历中的悬空边缘

[英]ArangoDB: handling dangling edges in a Traversal

I am using ArangoDB 2.8 and arangojs. 我正在使用ArangoDB 2.8和arangojs。

For some reasons, I've got dangling edges (I can not change that) in my data. 由于某些原因,我的数据有些悬空(我无法更改)。 In a traversal complex expander function, I am looking for a specific document, before pushing it in the connected data structure of the expander: 在遍历复杂的扩展器功能中,我正在寻找特定的文档,然后将其推入扩展器的连接数据结构中:

var refDoc = someColl.document(obj1[someProp]);

connected.push( edge:theEdge, vertex: refDoc });

How can I avoid the traversal expander being stopped by the error raised by someColl.document() if the searched document does not exist ? 如果搜索到的文档不存在,如何避免遍历扩展器因someColl.document()引发的错误而停止?

I've tried without success to use Node-style callbacks. 我尝试使用节点样式的回调没有成功。 Should I try (how?) to add es6-promise or bluebird on the modules on the server ? 我是否应该尝试(如何?)在服务器的模块上添加es6-promise或bluebird?

Thank you. 谢谢。

As Mike Williamson already sugested, try {} catch are the way to go: 正如迈克·威廉姆森(Mike Williamson)刚提出的建议, try {} catch是可行的方法:

const arangodb = require('@arangodb');

try {
 var refDoc = someColl.document(obj1[someProp]);
 connected.push( edge:theEdge, vertex: refDoc });
}
catch (ex) {
  if ((ex not instanceof ArangoError) or
      (ex.errorNum !== arangodb.ERROR_ARANGO_DOCUMENT_NOT_FOUND)) {
    throw(ex)
  }
}

So you can ignore the document not found error, but continue throwing other (maybe more fatal) errors. 因此,您可以忽略文档未找到错误,但继续引发其他(可能更致命)的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM