You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Daniel Gonzalez <go...@gonvaled.com> on 2012/06/22 13:47:42 UTC
Get total number of documents in view, without getting all documents
Hello,
I have a view which currently contains around 50 thousand documents.
I need to display the exact number of documents. For that I access the view
and take a look at the total_rows field.
I am doing this in pyhton, with python-couchdb, like this:
View(<my parameters>).total_rows
The problem is that this is taking a long time. It seems it is getting all
documents-
I am not sure whether this expected behaviour, or maybe I am doing
something wrong.
Is there a way to get the total number of documents in a view without
getting the documents themselves?
BR,
Daniel
Re: Get total number of documents in view, without getting all documents
Posted by Mark Hahn <ma...@hahnca.com>.
Use map/reduce with a simple sum function. Then the number will always be
available.
On Fri, Jun 22, 2012 at 6:17 AM, Daniel Gonzalez <go...@gonvaled.com>wrote:
> On Fri, Jun 22, 2012 at 2:05 PM, Dave Cottlehuber <da...@muse.net.nz>
> wrote:
>
> >
> > Either its retrieving all documents, or the view is being built while you
> > wait.
> >
> > Add limit=0 to your view parameters, to address the first issue.
> >
> > I guess you want to know the current # of documents, so if the view
> > hasn't been built yet, or needs updating you will need to wait. If you
> > are OK with an older result then you can use stale=ok.
> >
> > A+
> > Dave
> >
>
> Thanks, the limit=0 parameter is working. I thought that putting a limit
> parameter would affect the total_rows parameter returned by the view. I see
> now that total_rows refers to the number of documents in the view, not just
> the returned ones. Which makes sense, obviously. I was just very confused.
>
Re: Get total number of documents in view, without getting all documents
Posted by Daniel Gonzalez <go...@gonvaled.com>.
On Fri, Jun 22, 2012 at 2:05 PM, Dave Cottlehuber <da...@muse.net.nz> wrote:
>
> Either its retrieving all documents, or the view is being built while you
> wait.
>
> Add limit=0 to your view parameters, to address the first issue.
>
> I guess you want to know the current # of documents, so if the view
> hasn't been built yet, or needs updating you will need to wait. If you
> are OK with an older result then you can use stale=ok.
>
> A+
> Dave
>
Thanks, the limit=0 parameter is working. I thought that putting a limit
parameter would affect the total_rows parameter returned by the view. I see
now that total_rows refers to the number of documents in the view, not just
the returned ones. Which makes sense, obviously. I was just very confused.
Re: Get total number of documents in view, without getting all documents
Posted by Dave Cottlehuber <da...@muse.net.nz>.
On 22 June 2012 13:47, Daniel Gonzalez <go...@gonvaled.com> wrote:
> Hello,
>
> I have a view which currently contains around 50 thousand documents.
> I need to display the exact number of documents. For that I access the view
> and take a look at the total_rows field.
> I am doing this in pyhton, with python-couchdb, like this:
>
> View(<my parameters>).total_rows
>
> The problem is that this is taking a long time. It seems it is getting all
> documents-
> I am not sure whether this expected behaviour, or maybe I am doing
> something wrong.
>
> Is there a way to get the total number of documents in a view without
> getting the documents themselves?
>
> BR,
> Daniel
Either its retrieving all documents, or the view is being built while you
wait.
Add limit=0 to your view parameters, to address the first issue.
I guess you want to know the current # of documents, so if the view
hasn't been built yet, or needs updating you will need to wait. If you
are OK with an older result then you can use stale=ok.
A+
Dave