cost of collection.count?

87 views
Skip to first unread message

Maciej Dziardziel

unread,
Nov 27, 2009, 7:52:01 AM11/27/09
to mongodb-user
I'd like to know if getting amount of documents in collection
(collection.count()) is expensive
on large colelctions? In otherr words: does mongo keep tracks of this
number and can provide it instantly or does it perform something like
full scan or other calculations that can be slow when there is lot of
documents?

--
Maciej Dziardziel

Eliot Horowitz

unread,
Nov 27, 2009, 8:32:41 AM11/27/09
to mongod...@googlegroups.com
Count with no filter is fast, we keep track of the number of objects
in a collection
If you specify a query, then it has to so the query

On Nov 27, 2009, at 7:52 AM, Maciej Dziardziel <fie...@gmail.com>
wrote:
> --
>
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en
> .
>
>

Dwight Merriman

unread,
Nov 27, 2009, 10:29:00 AM11/27/09
to mongod...@googlegroups.com
yes it is instantaneous on large collections on a single mongod server

with sharding, it will be reasonably fast but get a bit slower as the collection grows

Maciej Dziardziel

unread,
Nov 27, 2009, 5:15:17 PM11/27/09
to mongodb-user
Why and how is it different in case of sharding?

> with sharding, it will be reasonably fast but get a bit slower as the
> collection grows

--
Maciej Dziardziel

Eliot Horowitz

unread,
Nov 27, 2009, 5:16:59 PM11/27/09
to mongod...@googlegroups.com
Because we have count each chunk separately to prevent miscounts
during migrations, etc...
Otherwise the number could be wrong at a given moment.
Reply all
Reply to author
Forward
0 new messages