我有一个带有Members和Pages的图形数据库,有些成员可以是ExpertOf的一些页面。我正在尝试构建一个查询,为给定页面的专家提供所有他们都是专家的页面。
总结一下,我有一个简单的db:Member ---(ExpertOf)---> Page
我(非常)工作的查询是
j
按预期工作,返回:
SELECT @rid,title,out('ExpertOf') AS expertises FROM
(SELECT expand(in('ExpertOf')) FROM Page WHERE @rid=16:299)
(顺便说一句,我想知道这是什么@rid:# - 2:0 ......)
但是现在,我不想拥有@rid页面,而是希望同时拥有@rid和title ...
我试过了:
{
"result": [
{
"@type": "d",
"@rid": "#-2:0",
"@version": 0,
"rid": "#17:0",
"title": "John Doe",
"expertises": [
"#16:299",
"#16:221",
"#15:160",
"#16:94",
"#16:714"
],
"@fieldTypes": "rid=x,expertises=z"
}
],
"notification": "Query executed in 0.057 sec. Returned 1 record(s)"
}
或(相同的结果)
SELECT @rid,title,out('ExpertOf').title AS expertises FROM
(SELECT expand(in('ExpertOf')) FROM Page WHERE @rid=16:299)
给出:
SELECT @rid,title,out('ExpertOf').include('title') AS expertises FROM
(SELECT expand(in('ExpertOf')) FROM Page WHERE @rid=16:299)
然后
"expertises": [
"Wave on string",
"USE A SLOPE",
"Spin coating",
"Gas hydrate",
"Mpemba effect"
],
返回:
SELECT @rid,title, out('ExpertOf').include('@rid','title') AS
expertises FROM (SELECT expand(in('ExpertOf')) FROM Page WHERE @rid=16:299)
虽然我希望
"expertises": [
"#16:299",
"#16:221",
"#15:160",
"#16:94",
"#16:714"
],
我已尝试 "expertises": [
{ "@rid":"#16:299", "title":"Wave on string" },
{ "@rid":"#16:221", "title":"USE A SLOPE" },
{ "@rid":"#15:160", "title":"Spin coating" },
{ "@rid":"#16:94", "title":"Gas hydrate" },
{ "@rid":"#16:714", "title":"Mpemba effect" }
],
或expand(out('ExpertOf').include('@rid','title'))
或unwind expertises
,如其他地方所述,等等......但没有任何疑问可以提供预期结果。
有没有办法获得这种结果? (我已经成功地使用了一个在Page上调用查询的函数,但我想知道这是否可以在一个查询中完成,如果我的解决方案有效)。
由于
答案 0 :(得分:1)
如果您正在使用HTTP并且想要获得嵌套的JSON,则可以使用fetchplans:
sails load
答案 1 :(得分:0)
代替这个
SELECT @rid,title,out('ExpertOf').include('title') AS expertises FROM
(SELECT expand(in('ExpertOf')) FROM Page WHERE @rid=16:299)
尝试做到这一点
SELECT @rid,title,out('ExpertOf')['title'] AS expertises FROM
(SELECT expand(in('ExpertOf')) FROM Page WHERE @rid=16:299)