使用簡單的SELECT FROM @rid
查詢:
CODE:
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;
輸出:
CODE:
[
{
"@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 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;
OUTPUT:
[
{
"@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
)的輸入功能參數:
CODE:
var db=orient.getGraph();
var result=db.command('sql',"select in('acts_In')[email protected] 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 IDS我要遍歷的列表,是結果數組內,其中包含1個對象,其中包含一個屬性「id」,它是一個數組。而這個最終數組就是我想要迭代的。 –