Aggregate - Is $project really effective in a two step ($match->$group) aggregate operation?

52 views
Skip to first unread message

Manoj Vivek

unread,
Apr 7, 2014, 8:24:53 AM4/7/14
to mongod...@googlegroups.com
Hi All,
The question here is, Will $project really necessary for in a two step aggregate with $match and $group.

Operation 1 : $match->$group
Operation 2 : $match->$project->$group

Will operation 2 be faster and efficient than Operation 1?

I see, Operation 2 with $project is unnecessary as it has only one step after the $project. no?

-Manoj Vivek

Asya Kamsky

unread,
Apr 7, 2014, 8:50:27 PM4/7/14
to mongodb-user
You do not need project unless it's actually computing a new field.
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user"
> group.
>
> For other MongoDB technical support options, see:
> http://www.mongodb.org/about/support/.
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mongodb-user/CANMwErOAiCD5_aQP9cPYo_8mHpOy2uw8M9B_AeagaOwdmV7cNg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Manoj Vivek

unread,
Apr 9, 2014, 2:07:29 PM4/9/14
to mongod...@googlegroups.com
We dont need $project to reduce the size of aggregate document?

Asya Kamsky

unread,
Apr 10, 2014, 2:05:40 AM4/10/14
to mongodb-user
No, you don't, the aggregation framework scans the full pipeline and
only passes through the fields that are actually going to be
needed/used in later stages.

Asya


On Wed, Apr 9, 2014 at 11:07 AM, Manoj Vivek <p.mano...@gmail.com> wrote:
> We dont need $project to reduce the size of aggregate document?
>
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user"
> group.
>
> For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
> ---
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d4b41c0e-24bc-4c76-bb75-b71506172125%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages