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

java - How to handle special characters while unmarshalling xml in JAXB -

ios - Pass NSDictionary from Javascript to Objective-c in JavascriptCore -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -