I have Query wich select some Datas from backet . It return [
“booksSelect”,
“carSelect”
]
I need to build a qury wich returning a values from document by KEYS “booksSelect”, “carSelect” , they can be in any deep in documents.
In ths example :
“booksSelect”: [
“fddc38be-728c-4858-9bc6-6e63557f2758”,
“d2a98652-cc7b-465d-ab48-be86b077e638”
]
SELECT d2.*
FROM (WITH Q1 AS (......add your subquery......)
SELECT ARRAY_FLATTEN(ARRAY (ARRAY v.[f] FOR v WITHIN {d} WHEN v.[f] IS NOT MISSING END) FOR f IN Q1 END,2) AS ks
FROM default d
WHERE ANY f IN Q1 SATISFIES ( ANY v WITHIN {d} SATISFIES v.[f] IS NOT MISSING END) END) AS d1
JOIN default AS d2 ON KEYS d1.ks;
ELSE
SELECT d2.*
FROM (
SELECT ARRAY_FLATTEN(ARRAY (ARRAY v.[f] FOR v WITHIN {d} WHEN v.[f] IS NOT MISSING END) FOR f IN Q1 END,2) AS ks
FROM default d
LET Q1 = (......add your subquery......)
WHERE ANY f IN Q1 SATISFIES ( ANY v WITHIN {d} SATISFIES v.[f] IS NOT MISSING END) END) AS d1
JOIN default AS d2 ON KEYS d1.ks;
Thanks a lot.
Please help me another
I need to replace ID on its documents
For exaple now
data:{
“en”: {
“booksSelect”: [
“fddc38be-728c-4858-9bc6-6e63557f2758”,
“d2a98652-cc7b-465d-ab48-be86b077e638”
],
result must be
data:{
“en”: {
“booksSelect”: [
{
id: “fddc38be-728c-4858-9bc6-6e63557f2758”, “data”: “test YYYYY”
},
{
id: “d2a98652-cc7b-465d-ab48-be86b077e638”, “data”: " test XXXX"
}
],
Can i do it in one query?
please tell me if it is possible to find a path by value for example value is fddc38be-728c-4858-9bc6-6e63557f2758,
path will by data.en.booksSelect
OR
I can replace ID fddc38be-728c-4858-9bc6-6e63557f2758 to the json
{
id: “fddc38be-728c-4858-9bc6-6e63557f2758”, “data”: “test YYYYY”
} as string may by ?
SELECT d.*, OBJECT_PUT(d.data,"en",OBJECT_PUT(d.data.en,"booksSelect"bs)) AS data
FROM default AS d
LET bs = (SELECT MTEA(b).id, b AS data
FROM default AS b USE KEYS d.data.en.booksSelect)
WHERE ...........;