count() vs find().count() vs MapReduce

2,000 views
Skip to first unread message

Adrien Mogenet

unread,
Jan 28, 2011, 2:17:53 PM1/28/11
to mongodb-user
Hi everyone,

In the documentation, section "Sharding Introduction" (http://
www.mongodb.org/display/DOCS/Sharding+Introduction), we can read :

> db.foo.find(...).count() || type=Variable || comments=Same as the corresponding find() operation
> db.foo.count() || type=Global || commments=parallel

But, when I open the source code, in shell/collection.js, line 419, we
can read that db.coll.count() cals db.coll.find().count().

The fact that db.coll.count() is just a helper makes sense, but now I
don't understand the documentation.

db.find() is sequential right ? and so is db.find().count() ?

Finally, I'm wondering if writing my own map/reduce jobs for
count( criteria ) would give better performances when running on a
scaling architecture that the mongo's count() ?

Eliot Horowitz

unread,
Jan 29, 2011, 12:31:22 AM1/29/11
to mongod...@googlegroups.com
I'm a bit unclear about what your'e asking.
What do you mean by sequential?
db.foo.count() and db.foo.find().count() are identical.

> --
> 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.
>
>

Adrien Mogenet

unread,
Jan 29, 2011, 5:57:04 AM1/29/11
to mongodb-user
You're right, I forgot some elements :)

If "_id" is my shard key, db.find( { foo : bar } ) (or without
criteria) becomes global, querying sequentially each shard ?

Then, db.find( { foo : bar } ).count() is also sequential ? (shard1,
then shard2....) instead of being parallel ?

Eliot Horowitz

unread,
Jan 29, 2011, 5:01:22 PM1/29/11
to mongod...@googlegroups.com
Currently they are sequential, though perhaps they should be made
parallel by default or optionally.
Can create a jira ticket to track if you want. jira.mongodb.org
Reply all
Reply to author
Forward
0 new messages