如何在OrientDB中的自定义javascript函数中从JSON中提取查询结果 [英] How to extract the result of a query from JSON inside a custom javascript function in OrientDB
问题描述
我在OrientDB Studio中创建了一个自定义javascript函数。该函数将rid作为参数并从该rid中执行select查询。
I created a custom javascript function in the OrientDB Studio. The function takes a rid as an argument and performs a select query from that rid.
var graph = orient.getGraph();
var res = graph.command( "sql", "select outE('Rel').inV('B').size() as lower_num from " + rid );
因此,此查询的结果是一个数字。根据此数字的值,函数应该执行不同的操作。我想知道如何从函数内的res变量中提取和使用该值。到目前为止我的所有尝试都失败了。如果我从函数返回res变量,结果如下所示:
So, the result of this query is a number. Depending on the value of this number the function should do different things. I wonder how to extract and use that value from the res variable inside the function. All my attempts have failed so far.. If I return the res variable from the function, the result looks like this:
[
{
"@type": "d",
"@rid": "#-2:1",
"@version": 0,
"lower_num": 2
}
]
所以,我试过以下(res [0] ['lower_num'] == 2); (res ['lower_num'] == 2)
并且没有任何效果..它们总是返回false。任何想法?
So, I tried the following ( res[0]['lower_num'] == 2 ); ( res['lower_num'] == 2 )
and nothing worked.. They always returned false. Any ideas?
推荐答案
OrientDB将ODocument对象放在结果集数组中。所以试试这个:
OrientDB put ODocument objects in the result set array. So try this:
return res[0].getRecord().field( "lower_num" );
这篇关于如何在OrientDB中的自定义javascript函数中从JSON中提取查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!