Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OrientDB Javascript服务器端函数内的结果迭代_Javascript_Function_Server Side_Orientdb - Fatal编程技术网

OrientDB Javascript服务器端函数内的结果迭代

OrientDB Javascript服务器端函数内的结果迭代,javascript,function,server-side,orientdb,Javascript,Function,Server Side,Orientdb,在javascript函数中,我有一些查询,例如: sQuery = "select in('E_Edge').@rid as id from ?"; result = db.command ('sql', sQuery,[givenId]); 如果我返回结果,它可以如下所示: [ { "@type":"d", "@rid":"#-2:0", "@version":0, "id":[ "#35:62", "#35:63", "#3

在javascript函数中,我有一些查询,例如:

sQuery = "select in('E_Edge').@rid as id from ?";
result = db.command ('sql', sQuery,[givenId]);
如果我返回结果,它可以如下所示:

[  
   {  
  "@type":"d",
  "@rid":"#-2:0",
  "@version":0,
  "id":[  
     "#35:62",
     "#35:63",
     "#35:64",
     "#35:65",
     "#35:69"
  ],
  "@fieldTypes":"id=z"
   }
]
如果我想获得ID列表,我可以执行以下操作:

var ids= result[0].getProperty("id");
如果我返回它,我会得到扩展的ID,即带有这些ID的节点列表

但是,如果我想迭代它并执行其他操作,
ids.length
不作为属性存在,size()不可用


如何迭代列表?

如果您想迭代列表(如果我理解正确)以执行其他操作,您可以尝试以下操作:

var db=orient.getGraph();
var result=db.command('sql',"select in('E_Edge').@rid as id from Test where @rid='"+rid+"'");

for(i=0;i<result.length;i++)
{
  var ids=result[i].getProperty("id");
  print(ids);
}
var db=orient.getGraph();
var result=db.command('sql','select in('E_Edge')。@rid作为测试的id,其中@rid='“+rid+”);

对于(i=0;i如果您想迭代列表(如果我理解正确)以执行其他操作,您可以尝试以下操作:

var db=orient.getGraph();
var result=db.command('sql',"select in('E_Edge').@rid as id from Test where @rid='"+rid+"'");

for(i=0;i<result.length;i++)
{
  var ids=result[i].getProperty("id");
  print(ids);
}
var db=orient.getGraph();
var result=db.command('sql','select in('E_Edge')。@rid作为测试的id,其中@rid='“+rid+”);

对于(i=0;i我用这种结构尝试了你的案例:

create class Person extends V
create class Movie extends V
create class acts_In extends E
create class directed extends E
create class friend extends E
create class rated extends E

create property Person.name String
create property Person.surname String
create property Movie.title String

create vertex Person set name="Tom", surname="Hanks"
create vertex Person set name="Robin", surname="Wright"
create vertex Person set name="Helen", surname="Hunt"
create vertex Person set name="Robert", surname="Zemeckis"
create vertex Person set name="Russell", surname="Crowe"
create vertex Person set name="Ben", surname="Affleck"
create vertex Person set name="Kevin", surname="Macdonald"
create vertex Person set name="John"
create vertex Person set name="Mark"
create vertex Person set name="Paul"
create vertex Person set name="Mel", surname="Gibson"
create vertex Person set name="Nancy", surname="Meyers"
create vertex Movie set title="Forrest Gump"
create vertex Movie set title="Cast Away"
create vertex Movie set title="State of Play"
create vertex Movie set title="What Women Want"

create edge acts_In from (select from Person where name="Tom" and surname="Hanks") to (select from Movie where title="Forrest Gump")
create edge acts_In from (select from Person where name="Tom" and surname="Hanks") to (select from Movie where title="Cast Away")
create edge acts_In from (select from Person where name="Robin" and surname="Wright") to (select from Movie where title="Forrest Gump")
create edge acts_In from (select from Person where name="Robin" and surname="Wright") to (select from Movie where title="State of Play")
create edge acts_In from (select from Person where name="Helen" and surname="Hunt") to (select from Movie where title="Cast Away")
create edge acts_In from (select from Person where name="Helen" and surname="Hunt") to (select from Movie where title="What Women Want")
create edge acts_In from (select from Person where name="Mel" and surname="Gibson") to (select from Movie where title="What Women Want")
create edge acts_In from (select from Person where name="Russell" and surname="Crowe") to (select from Movie where title="State of Play")
create edge acts_In from (select from Person where name="Ben" and surname="Affleck") to (select from Movie where title="State of Play")
create edge friend from (select from Person where name="Mel" and surname="Gibson") to (select from Person where name="Helen" and surname="Hunt")
create edge friend from (select from Person where name="Ben" and surname="Affleck") to (select from Person where name="Russell" and surname="Crowe")
create edge directed from (select from Movie where title="What Women Want") to (select from Person where name="Nancy" and surname="Meyers")
create edge directed from (select from Movie where title="Cast Away") to (select from Person where name="Robert" and surname="Zemeckis")
create edge directed from (select from Movie where title="Forrest Gump") to (select from Person where name="Robert" and surname="Zemeckis")
create edge directed from (select from Movie where title="State of Play") to (select from Person where name="Kevin" and surname="Macdonald")
create edge rated from (select from Movie where title="What Women Want") to (select from Person where name="Paul")
create edge rated from (select from Movie where title="Cast Away") to (select from Person where name="John")
create edge rated from (select from Movie where title="Forrest Gump") to (select from Person where name="Mark")
create edge rated from (select from Movie where title="State of Play") to (select from Person where name="John")
查询:选择在
电影
中使用
@rid 13:2
(“播放状态”)表演的演员

现在,您可以尝试不同的方法来检索您要查找的结果:

  • 使用简单的
    从@rid
    查询中选择:

    代码

    var db = orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var sQuery = "select from ?";
    var result = db.command('sql',sQuery, [givenId]);
    for(i=0;i<result.length;i++){
      var in_acts_In = result[i].getRecord().field('in_acts_In.out');
      if(in_acts_In!=null){
        var actorsIter=in_acts_In.iterator();
        if(actorsIter!=null){
          while(actorsIter.hasNext()){
            var iteratedActor=actorsIter.next();
            actorsList.push(iteratedActor.getRecord());
          }
        }
      }
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var result=db.command('sql',"select expand(in('acts_In')) from ?",[givenId]);
    for(i=0;i<result.length;i++)
    {
      var actor=result[i].getRecord();
      actorsList.push(actor);;
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var result=db.command('sql',"select in('acts_In').@rid as id from "+rid);
    for(i=0;i<result.length;i++)
    {
      var idList=result[i].getProperty("id");
    }
    return idList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
  • expand()
    查询结果:

    代码

    var db = orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var sQuery = "select from ?";
    var result = db.command('sql',sQuery, [givenId]);
    for(i=0;i<result.length;i++){
      var in_acts_In = result[i].getRecord().field('in_acts_In.out');
      if(in_acts_In!=null){
        var actorsIter=in_acts_In.iterator();
        if(actorsIter!=null){
          while(actorsIter.hasNext()){
            var iteratedActor=actorsIter.next();
            actorsList.push(iteratedActor.getRecord());
          }
        }
      }
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var result=db.command('sql',"select expand(in('acts_In')) from ?",[givenId]);
    for(i=0;i<result.length;i++)
    {
      var actor=result[i].getRecord();
      actorsList.push(actor);;
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var result=db.command('sql',"select in('acts_In').@rid as id from "+rid);
    for(i=0;i<result.length;i++)
    {
      var idList=result[i].getProperty("id");
    }
    return idList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
  • 使用输入函数参数(
    rid
    ,在我的情况下,其值为
    13:2
    ):

    代码

    var db = orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var sQuery = "select from ?";
    var result = db.command('sql',sQuery, [givenId]);
    for(i=0;i<result.length;i++){
      var in_acts_In = result[i].getRecord().field('in_acts_In.out');
      if(in_acts_In!=null){
        var actorsIter=in_acts_In.iterator();
        if(actorsIter!=null){
          while(actorsIter.hasNext()){
            var iteratedActor=actorsIter.next();
            actorsList.push(iteratedActor.getRecord());
          }
        }
      }
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var result=db.command('sql',"select expand(in('acts_In')) from ?",[givenId]);
    for(i=0;i<result.length;i++)
    {
      var actor=result[i].getRecord();
      actorsList.push(actor);;
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var result=db.command('sql',"select in('acts_In').@rid as id from "+rid);
    for(i=0;i<result.length;i++)
    {
      var idList=result[i].getProperty("id");
    }
    return idList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    

  • 希望对您有所帮助

    我用以下结构尝试了您的案例:

    create class Person extends V
    create class Movie extends V
    create class acts_In extends E
    create class directed extends E
    create class friend extends E
    create class rated extends E
    
    create property Person.name String
    create property Person.surname String
    create property Movie.title String
    
    create vertex Person set name="Tom", surname="Hanks"
    create vertex Person set name="Robin", surname="Wright"
    create vertex Person set name="Helen", surname="Hunt"
    create vertex Person set name="Robert", surname="Zemeckis"
    create vertex Person set name="Russell", surname="Crowe"
    create vertex Person set name="Ben", surname="Affleck"
    create vertex Person set name="Kevin", surname="Macdonald"
    create vertex Person set name="John"
    create vertex Person set name="Mark"
    create vertex Person set name="Paul"
    create vertex Person set name="Mel", surname="Gibson"
    create vertex Person set name="Nancy", surname="Meyers"
    create vertex Movie set title="Forrest Gump"
    create vertex Movie set title="Cast Away"
    create vertex Movie set title="State of Play"
    create vertex Movie set title="What Women Want"
    
    create edge acts_In from (select from Person where name="Tom" and surname="Hanks") to (select from Movie where title="Forrest Gump")
    create edge acts_In from (select from Person where name="Tom" and surname="Hanks") to (select from Movie where title="Cast Away")
    create edge acts_In from (select from Person where name="Robin" and surname="Wright") to (select from Movie where title="Forrest Gump")
    create edge acts_In from (select from Person where name="Robin" and surname="Wright") to (select from Movie where title="State of Play")
    create edge acts_In from (select from Person where name="Helen" and surname="Hunt") to (select from Movie where title="Cast Away")
    create edge acts_In from (select from Person where name="Helen" and surname="Hunt") to (select from Movie where title="What Women Want")
    create edge acts_In from (select from Person where name="Mel" and surname="Gibson") to (select from Movie where title="What Women Want")
    create edge acts_In from (select from Person where name="Russell" and surname="Crowe") to (select from Movie where title="State of Play")
    create edge acts_In from (select from Person where name="Ben" and surname="Affleck") to (select from Movie where title="State of Play")
    create edge friend from (select from Person where name="Mel" and surname="Gibson") to (select from Person where name="Helen" and surname="Hunt")
    create edge friend from (select from Person where name="Ben" and surname="Affleck") to (select from Person where name="Russell" and surname="Crowe")
    create edge directed from (select from Movie where title="What Women Want") to (select from Person where name="Nancy" and surname="Meyers")
    create edge directed from (select from Movie where title="Cast Away") to (select from Person where name="Robert" and surname="Zemeckis")
    create edge directed from (select from Movie where title="Forrest Gump") to (select from Person where name="Robert" and surname="Zemeckis")
    create edge directed from (select from Movie where title="State of Play") to (select from Person where name="Kevin" and surname="Macdonald")
    create edge rated from (select from Movie where title="What Women Want") to (select from Person where name="Paul")
    create edge rated from (select from Movie where title="Cast Away") to (select from Person where name="John")
    create edge rated from (select from Movie where title="Forrest Gump") to (select from Person where name="Mark")
    create edge rated from (select from Movie where title="State of Play") to (select from Person where name="John")
    
    查询:选择在
    电影
    中使用
    @rid 13:2
    (“播放状态”)表演的演员

    现在,您可以尝试不同的方法来检索您要查找的结果:

  • 使用简单的
    从@rid
    查询中选择:

    代码

    var db = orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var sQuery = "select from ?";
    var result = db.command('sql',sQuery, [givenId]);
    for(i=0;i<result.length;i++){
      var in_acts_In = result[i].getRecord().field('in_acts_In.out');
      if(in_acts_In!=null){
        var actorsIter=in_acts_In.iterator();
        if(actorsIter!=null){
          while(actorsIter.hasNext()){
            var iteratedActor=actorsIter.next();
            actorsList.push(iteratedActor.getRecord());
          }
        }
      }
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var result=db.command('sql',"select expand(in('acts_In')) from ?",[givenId]);
    for(i=0;i<result.length;i++)
    {
      var actor=result[i].getRecord();
      actorsList.push(actor);;
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var result=db.command('sql',"select in('acts_In').@rid as id from "+rid);
    for(i=0;i<result.length;i++)
    {
      var idList=result[i].getProperty("id");
    }
    return idList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
  • expand()
    查询结果:

    代码

    var db = orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var sQuery = "select from ?";
    var result = db.command('sql',sQuery, [givenId]);
    for(i=0;i<result.length;i++){
      var in_acts_In = result[i].getRecord().field('in_acts_In.out');
      if(in_acts_In!=null){
        var actorsIter=in_acts_In.iterator();
        if(actorsIter!=null){
          while(actorsIter.hasNext()){
            var iteratedActor=actorsIter.next();
            actorsList.push(iteratedActor.getRecord());
          }
        }
      }
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var result=db.command('sql',"select expand(in('acts_In')) from ?",[givenId]);
    for(i=0;i<result.length;i++)
    {
      var actor=result[i].getRecord();
      actorsList.push(actor);;
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var result=db.command('sql',"select in('acts_In').@rid as id from "+rid);
    for(i=0;i<result.length;i++)
    {
      var idList=result[i].getProperty("id");
    }
    return idList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
  • 使用输入函数参数(
    rid
    ,在我的情况下,其值为
    13:2
    ):

    代码

    var db = orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var sQuery = "select from ?";
    var result = db.command('sql',sQuery, [givenId]);
    for(i=0;i<result.length;i++){
      var in_acts_In = result[i].getRecord().field('in_acts_In.out');
      if(in_acts_In!=null){
        var actorsIter=in_acts_In.iterator();
        if(actorsIter!=null){
          while(actorsIter.hasNext()){
            var iteratedActor=actorsIter.next();
            actorsList.push(iteratedActor.getRecord());
          }
        }
      }
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var givenId = '13:2';
    var actorsList=[];
    var result=db.command('sql',"select expand(in('acts_In')) from ?",[givenId]);
    for(i=0;i<result.length;i++)
    {
      var actor=result[i].getRecord();
      actorsList.push(actor);;
    }
    return actorsList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    
    var db=orient.getGraph();
    var result=db.command('sql',"select in('acts_In').@rid as id from "+rid);
    for(i=0;i<result.length;i++)
    {
      var idList=result[i].getProperty("id");
    }
    return idList;
    
    [
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Robin",
            "surname": "Wright",
            "out_acts_In": [
                "#14:2",
                "#14:3"
            ],
            "@fieldTypes": "out_acts_In=g"
        },
        {
            "@type": "d",
            "@rid": "#12:4",
            "@version": 3,
            "@class": "Person",
            "name": "Russell",
            "surname": "Crowe",
            "out_acts_In": [
                "#14:7"
            ],
            "in_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,in_friend=g"
        },
        {
            "@type": "d",
            "@rid": "#12:5",
            "@version": 3,
            "@class": "Person",
            "name": "Ben",
            "surname": "Affleck",
            "out_acts_In": [
                "#14:8"
            ],
            "out_friend": [
                "#16:1"
            ],
            "@fieldTypes": "out_acts_In=g,out_friend=g"
        }
    ]
    

  • 希望有帮助,您好,这不起作用,因为result.length是1。我要迭代的id列表位于result数组中,该数组包含1个对象,其中包含一个属性“id”,这是一个数组。最后一个数组是我要迭代的。嗨,这不起作用,因为result.length是1。我要迭代的id列表在结果数组中,它包含1个对象,其中包含一个属性“id”,这是一个数组。最后一个数组就是我要迭代的。嗨,Mihai,你有机会尝试这个函数吗?嗨,Mihai,你有机会尝试这个函数吗?