Sql 这个结果的字符串?
Sql string for this result?
我想对 collection 中的文档进行简单的转换。我想改造这个:
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd",
"title": "Manager",
"company": "MyCompany"
},
"events": {
"eventA": {
"questions": [
{
"id": 123,
"answer": "hello"
},
{
"id": 456,
"answer": "world"
}
]
}
},
"id": "1d7070f0-a00b-46e8-87ee-67ba8e192639"
}
进入这个:
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd",
},
"events": {
"eventA": {
"questions": [
{
"id": 123
},
{
"id": 456
}
]
}
},
"id": "1d7070f0-a00b-46e8-87ee-67ba8e192639"
}
我只想从档案中删除 "title" 和 "company",并从 events.eventA.questions[] 中删除 "answer"。
我认为这应该相当简单,但我一直没弄明白。到目前为止,我提出了这个查询
SELECT {"firstName": c.dossier.firstName, "lastName": c.dossier.lastName} AS dossier,
{
"questions": {"id": q.id}
} as eventA
from c
join q in c.events.eventA.questions
WHERE c.id = '1d7070f0-a00b-46e8-87ee-67ba8e192639'
但它给了我错误的结果;
[
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd"
},
"eventA": {
"questions": {
"id": 123
}
}
},
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd"
},
"eventA": {
"questions": {
"id": 456
}
}
}
]
我做错了什么?
我在发现 ARRAY 函数后就明白了。最后的sql是
SELECT {"firstName": c.dossier.firstName, "lastName": c.dossier.lastName} AS dossier,
{
"questions": ARRAY(SELECT q.id from q in c.events.eventA.questions)
} as eventA
from c
WHERE c.id = '1d7070f0-a00b-46e8-87ee-67ba8e192639'
我知道这会很简单。 :)
我想对 collection 中的文档进行简单的转换。我想改造这个:
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd",
"title": "Manager",
"company": "MyCompany"
},
"events": {
"eventA": {
"questions": [
{
"id": 123,
"answer": "hello"
},
{
"id": 456,
"answer": "world"
}
]
}
},
"id": "1d7070f0-a00b-46e8-87ee-67ba8e192639"
}
进入这个:
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd",
},
"events": {
"eventA": {
"questions": [
{
"id": 123
},
{
"id": 456
}
]
}
},
"id": "1d7070f0-a00b-46e8-87ee-67ba8e192639"
}
我只想从档案中删除 "title" 和 "company",并从 events.eventA.questions[] 中删除 "answer"。
我认为这应该相当简单,但我一直没弄明白。到目前为止,我提出了这个查询
SELECT {"firstName": c.dossier.firstName, "lastName": c.dossier.lastName} AS dossier,
{
"questions": {"id": q.id}
} as eventA
from c
join q in c.events.eventA.questions
WHERE c.id = '1d7070f0-a00b-46e8-87ee-67ba8e192639'
但它给了我错误的结果;
[
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd"
},
"eventA": {
"questions": {
"id": 123
}
}
},
{
"dossier": {
"firstName": "Mortimer",
"lastName": "Snurd"
},
"eventA": {
"questions": {
"id": 456
}
}
}
]
我做错了什么?
我在发现 ARRAY 函数后就明白了。最后的sql是
SELECT {"firstName": c.dossier.firstName, "lastName": c.dossier.lastName} AS dossier,
{
"questions": ARRAY(SELECT q.id from q in c.events.eventA.questions)
} as eventA
from c
WHERE c.id = '1d7070f0-a00b-46e8-87ee-67ba8e192639'
我知道这会很简单。 :)