How to access array element using N1Ql in couchbase-4.0

n1ql
query

#1

Hello,

I have below document…Here, i have call history inside the “calls” array.

"calls": [
{
  "times": {
    "start": "2016-05-02 13:32:35+00:00 PM",
    "end": "2016-05-02 13:35:09+00:00 PM",
    "during": "1970-01-01 00:03:00+00:00 AM"
  },
  "id": "51229802-4107-495a-ad03-24c3af970e69",
  "callerId": "1005671461870990306",
  "type": "outcoming",
  "payments": {
    "type": "free"
  }
}, {
  "times": {
    "start": "2016-05-02 13:32:35+00:00 PM",
    "end": "2016-05-02 13:35:09+00:00 PM",
    "during": "1970-01-01 00:03:00+00:00 AM"
  },
  "id": "51229802-4107-495a-ad03-24c3af970e69",
  "calleeId": "1002091461870375633",
  "type": "incoming",
  "payments": {
    "type": "free"
  }
}
  ],

My question is?.

1.How can i filter call history based “start” and “end” time.
2.I am facing problem of accessing value of “from” and “end” time.

Thank you…


#2

This will get you the documents for a specific start time.

SELECT META().id as CBKey , calls[*].times.start as StartTime , calls[*].times.end as EndTime FROM bucket WHERE ANY x IN calls SATISFIES x.times.start = '{some time}' END;


#3

Thank you for your reply,

When i execute this query, i got below error,

{"code":3000,"msg":"syntax error - at start"}

Can you please help me…to figure out…


#4

I wonder if start isn’t a N1QL keyword, and should as such be escaped with backticks:

calls[*].times.`start`

Have you tried that?