How to query from view with combined key?

Hi all,

after creating a view with a combined key

function (doc, meta)
{
emit([doc.code, doc.year, doc.month, doc.day], some_value_to_be_summed);
}

and I’ve sent it to production after testing. The combined key can be used for grouping, e.g. summing per code per year, or per month.

My question: Having done this for the ACCOUNTS bucket, how can I get all values for code A1234 for year 2012 using N1QL or Linq?

Thanx for your help!

N1QL (Will not use map-reduce view) directly uses bucket data, Checkout https://blog.couchbase.com/comparing-couchbase-views-couchbase-n1ql-indexing/

SELECT  d.month, d.day, SUM(d. some_value_to_be_summed) AS s
FROM default AS d
WHERE d.code = "A1234" AND d.year = 2012
GROUP BY d.month, d.day

Ow OK. So I do not gain anything with a view when using N1QL? Is that right? If so, when IS the map-reduce view used?

Map reduce views can be used with curl or API’s in SDK directly.

Correct, found that information on https://docs.couchbase.com/server/6.0/learn/views/views-querying.html. Thanx!