【问题标题】:how to add multiple edges using javascript function in orientDB如何在 orientDB 中使用 javascript 函数添加多个边
【发布时间】:2018-03-13 10:18:35
【问题描述】:

我使用 javascript 函数添加了多个节点,并希望在尝试编写 for 循环时添加边来连接它们,它会引发以下异常:

com.orientechnologies.orient.core.exception.OSerializationException:无法序列化无效链接:#57:-2 在嵌入式会话中

如果我在没有 for 循环的情况下编写相同的查询,它将被执行。

var g = orient.getGraph();
for (var i = 0 ; i < 5 ; i ++ ){
var title ="post_0";
var company_name = "Company_0";
var c = "create edge HasInterest from (select from post where Title = '" + 
title + "') to (select from Interest where      Name = 'Recruitment')"; 
    g.command("sql",c,[]);
}

【问题讨论】:

  • for 循环是否应该遍历 post_0、post_1 等?
  • 是的,我已经上传了硬编码版本,它将是“post_” + i

标签: javascript orientdb graph-databases


【解决方案1】:

您缺少一个 commit() 语句,因为您正在使用这样的循环:

var g = orient.getGraph();
for (var i = 0 ; i < 5 ; i ++ )
{
    var title = "post_" + i;
    var company_name = "Company_" + i;
    var c = "create edge HasInterest from (select from post where Title = '" +
             title + "') to (select from Interest where Name = 'Recruitment')";
    g.command("sql",c,[]);
    g.commit();
}

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多