I have this basic query:
SELECT *
FROM data
WHERE Name LIKE "%Doe%"
The bucket name is data
- and it returns this test data:
[
{
"data": {
"Closed": true,
"Date": "2017-02-24T16:59:41+0100",
"Email": "john.doe@gmail.com",
"Heading": "Test af feedback...",
"Key": "4893D459F92BAEAEC12580D10057DCAF",
"Message": "Hej!",
"Name": "Mr. Doe",
"RelatedUrl": "clubadmin.xsp",
"RevisionInfo": {
"Created": "2017-02-24T16:59:41+0100",
"CreatedBy": "John Dalsgaard/BA171123846CEBF1C1257CB2002DA330/Fangst",
"Updates": [
{
"Modified": "2018-04-16T13:17:49+0200",
"ModifiedBy": "John Dalsgaard/BA171123846CEBF1C1257CB2002DA330/Fangst"
}
]
},
"Subject": "9",
"Type": "Feedback",
"Unid": "4893D459F92BAEAEC12580D10057DCAF",
"UserKey": "BA171123846CEBF1C1257CB2002DA330"
}
},
{
"data": {
"Closed": true,
"Date": "2017-06-19T15:18:28+0200",
"Email": "john@doe.com",
"Heading": "Test",
"Key": "539B0D9C73696D47C125814400492045",
"Message": "... fra app :-)",
"Name": "John Doe",
"RelatedUrl": "Fra mobil app",
"RevisionInfo": {
"Created": "2017-06-19T15:18:44+0200",
"CreatedBy": "anonymous",
"Updates": [
{
"Modified": "2018-04-16T15:44:51+0200",
"ModifiedBy": "John Dalsgaard/BA171123846CEBF1C1257CB2002DA330/Fangst"
},
{
"Modified": "2018-04-16T15:45:10+0200",
"ModifiedBy": "John Dalsgaard/BA171123846CEBF1C1257CB2002DA330/Fangst"
}
]
},
"Subject": "9",
"Type": "Feedback",
"Unid": "539B0D9C73696D47C125814400492045",
"UserKey": "587CE5200641ABD9C1257E500051DDCD"
}
},
{
"data": {
"Closed": false,
"Date": "2016-05-05T22:26:07+0200",
"Email": "j.doe@post.cybercity.dk",
"Heading": "Login",
"Key": "46A8A36707A745BAC1257FAA007040DF",
"Message": "Hej\n\nJeg kan ikke logge ind selvom jeg bruger det korrekte kodeord og den mail jeg er oprettet med? Kan i hjælpe mig?\n\nVenligst\n\nSteffen Skovgaard",
"Name": "Mrs. Doe",
"RelatedUrl": "index.xsp",
"RevisionInfo": {
"Created": "2016-05-05T22:26:07+0200",
"CreatedBy": "anonymous"
},
"Subject": "9",
"Type": "Feedback",
"Unid": "CFF25D38E4BB7A72C1258271004C42DE"
}
}
]
It still confuses me a little that the name of the bucket is returned as part of the result (and that I have to use that when I process the returned rows in the Java SDK) - but that is another thing
I have tried to unnest
the RevisionInfo
node of the above dataset. But i cannot find the right syntax as it returns an empty result. I think something like this ought to give me something:
SELECT *
FROM data
UNNEST RevisionInfo
or
SELECT *
FROM data
UNNEST data.RevisionInfo
and I have also tried to use the aliases:
SELECT r.*
FROM data d
UNNEST d.RevisionInfo r
What am I doing wrong here??? I have just created on primary index - but as I understand it I should still be able to use unnest
anyway.
The real query that I am trying to build is one that will return me the latest Created
or Modified
of the entire dataset.
I am new to N1QL so still struggling a little with the best approach to doing things - and next how to do it most efficient. I’m using the Community Server version 5.0.1
I am trying this out using the Query Editor on the builtin web page of the Couchbase server on port 8091