SystematicFrank
SystematicFrank

Reputation: 17269

Alternative compound key ranges in CouchDB

Assuming a mapreduce function representing object relationships like:

function (doc) {
    emit([doc.source, doc.target, doc.name], null);
}

The normal example of filtering a compound key is something like:

startKey = [ a_source ]
endKey   = [ a_source, {} ]

That should provide a list of all objects referenced from a_source

Now I want the oposite and I am not sure if that is possible. I have not been able to find an example where the variant part comes first, like:

startKey = [ *simbol_first_match* , a_destination ]
endKey   = [ {} , a_destination ]

Is that posible? Are compound keys (1) filter and (2) sort operations within a query limited to the order of the elements appear in the key?

I know I could define another view/mapreduce, but I would like to avoid the extra disk space cost if possible.

Upvotes: 0

Views: 173

Answers (1)

thriqon
thriqon

Reputation: 2488

No, you can't do that. See here where I explained how keys work in view requests with CouchDB.

Compound keys are nothing special, no filtering or anything. Internally you have to imagine that there is no array anymore. It's just syntactic sugar for us developers. So [a,b] - [a,c] is treated just like 'a_b' - 'a_c' (with _ being a special delimiter).

Upvotes: 1

Related Questions