couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Barnes <mrtr...@gmail.com>
Subject Re: Can I get just the keys from a view? [SEC=UNCLASSIFIED]
Date Tue, 15 Jun 2010 02:50:34 GMT
The document API is a view as well, where the value emitted for each doc 
is null.

You say that each of the rows in your view has a large value object, but 
that you don't need it? Then why are you emitting it in the first place?
If you have two different use cases;
  a) Fetching lots of keys
  b) Fetching the value for a particular key
Then the solution may be to have two views - one emitting null 
values(a), and the other emitting real values(b). Whether the overhead 
of an extra view is worthwhile will depend on your usage patterns.

Another option might be - if b is not performed often, discard that 
view; fetch the document itself and calculate the value client-side when 
needed.

For example, I had a need to filter role docs by a set of attributes, so 
I emitted a view record for every attribute, for every role doc. (So the 
key looked like: [group_id, attrib_name, attrib_value])
To get roles on a group with active status;
startkey=['mygroup', 'status', 'active']
endkey=['mygroup', 'status', 'active', {}]
It worked well enough, til I realised that it was far simpler (and more 
flexible) just to key by group_id; there would never be more than 50 or 
so records with that key, and I could filter the list client-side. As a 
result, my view shrunk by a factor of 10.

-Patrick

On 15/06/2010 12:26 PM, Lowry, Matthew wrote:
> Hi folks. A Couch newbie here with a question regarding the view API.
>
> Is there any way that I can query a view and get just the key for each
> row, and omit the value?
>
> The reason I ask is I'm working with a view that generates a massive
> amount of data - each document in the database generates many hundreds
> of rows in the view. Each row has a large value object. But all I want
> to do is get the keys. So it's wasting a massive amount of time and
> resources, both client and server side, to have to pull both the key and
> value object for every row in the view when all I want to see is the
> key.
>
> So is there actually a mechanism in the view API to pull just the key
> from each row of a view? And if not, why not? That would be curiously
> asymmetrical with the document API, which allows me to get the IDs of
> all the documents without requesting the documents themselves.
>
> Cheers.
>
> IMPORTANT: This email remains the property of the Department of Defence and is subject
to the jurisdiction of section 70 of the Crimes Act 1914. If you have received this email
in error, you are requested to contact the sender and delete the email.
>

Mime
View raw message