couchbase - N1QL: Using select directly on arrays -


i having problems on querying objects inside array.

i have sample document

{   ...   status: 'active',   current: { ... },   history: [     {       id: '73bae187-1101-4fb3-a71a-2bbf90026eb3',       date: '2017-03-28t09:32:22.884z',       content: 'this second content'     },     {       id: 'd6a6c63d-42db-4ef5-88e9-616cfe539a57',       date: '2017-03-25t09:32:22.884z',       content: 'this first content'     },     {       id: '3fbdb846-2b55-4ff8-8960-86997ef31556',       schedule: '1970-01-01t00:00:00.000z',       content: 'this old content'     }   ] } 

i want directly query history array sub document in want apply date filters.

is possible in n1ql retrieve history array contain objects satisfies condition?

can apply limit can control number of the returned objects inside array?

i tried queries using splicing [0:$1] limit input doesn't work when limit greater array size.

thanks help.

try either of following approach:

select h[0:least(array_length(h), $arraylimit)] h default d let h = array v v in d.history when v.id  in  [ 'xyz', 'pqr'] end; 

or:

select h[0:least(array_length(h),$limit)] h (select array_agg(h) h  default d unnest d.history h h.id in  [ 'xyz', 'pqr'] group d) q; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

python - Error: Unresolved reference 'selenium' What is the reason? -

asp.net ajax - Jquery scroll to element just goes to top of page -