[英]How to extract the result of a db.command query from JSON inside a custom javascript function in OrientDB
I have this SQL code in this custom javascript.我在这个自定义 javascript 中有这个 SQL 代码。
var inLinkNodes = db.command('sql','SELECT in() FROM node where @rid = ' + relateNode);
var inLinkNodes = db.command('sql','SELECT in() FROM node where @rid = ' + relatedNode);
. .
return inLinkNodes;
返回 inLinkNodes;
when I return this variable, I get the following output:当我返回这个变量时,我得到以下输出:
Output:输出:
[ [
{ {
"@type": "d", "@type": "d",
"@rid": "#-2:0", "@rid": "#-2:0",
"@version": 0, “@版本”:0,
"in": [ “在”: [
"#17:9" “#17:9”
], ],
"@fieldTypes": "in=z" "@fieldTypes": "in=z"
} }
] ]
I tried this following command:我尝试了以下命令:
return inLinkNodes[0].getRecord().field( "in" );
返回 inLinkNodes[0].getRecord().field("in");
but this gives this following output:但这给出了以下输出:
[
[
{{
"@type": "d","@type": "d",
"@rid": "#17:9","@rid": "#17:9",
"@version": 2,“@版本”:2,
"@class": "node","@class": "节点",
"out_isLinkedTo": [“out_isLinkedTo”:[
"#13:25"“#13:25”
],],
"@fieldTypes": "out_isLinkedTo=g""@fieldTypes": "out_isLinkedTo=g"
}}
]]
How to extract only "#17:9" as a string output?如何仅提取“#17:9”作为字符串输出?
你可以尝试这样的事情:
var inLinkNodes = db.command('sql','select expand(@this.exclude('@type','@rid','@version','@class')) from (SELECT in() FROM node where @rid = ' + relateNode + ')');
You can do this :你可以这样做 :
var inLinkNodes = db.command('sql','SELECT in().@rid FROM ' + relateNode);
Hope it helps !希望能帮助到你 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.