How to use view with composite keys?

Hi,
I'm using python to take data from view with composite key:
function (doc, meta) {
if (doc.type == "feedData")
{
dt = dateToArray(doc.at);
dt.unshift(doc.feedId);
emit(dt, doc.v);
}
}

In python I have the following:

mapkeyRange = [
["feedId", 2013, 7, 18, 0, 0, 0],
["feedId", 2013, 7, 18, 10, 0, 0]]

q = couchbase.views.params.Query(
stale=False,
reduce=False,
mapkey_range=mapkeyRange)

feedData = bucket.query("feedData", "vFeedData", query=q)

However, this does not work at all.
What is the proper way to do that?

Thanks in advance.
Ivan

1 Answer

« Back to question.

Hello,

I have just tested on my cluster and python app, and it is working as expected.

1- Have you published your view in production?
2- Have you tested from the REST API/Console

Here the code that I have used:

#!/usr/bin/env python
from couchbase import Couchbase
from couchbase.views.params import UNSPEC, Query
 
cb = Couchbase.connect(bucket='default')
 
q = Query(
    mapkey_range=[
        ["feedId", 2013, 7, 18, 0, 0, 0],
        ["feedId", 2013, 7, 18, 10, 0, 0]]
)
 
rows = cb.query("test", "test", query=q )
 
for row in rows:
    print "Key \"%s\". ID '%s'" % (row.key, row.docid)

Regards
Tug
@tgrall