Remove _id after grouping stage in aggregation

1,158 views
Skip to first unread message

Mukul Sharma

unread,
May 29, 2014, 7:56:13 AM5/29/14
to mongod...@googlegroups.com
Version : 2.6.1

I'm using the group aggregation in mongodb, & writing the result to a collection using $out.

Is there way to prevent the _id field in aggregation result from going into the newly created collection.

One way using the $project stage, & removing _id & including the others.

Is there a better or neat way of doing this ?

Stephen Steneker

unread,
Jun 16, 2014, 2:25:00 AM6/16/14
to mongod...@googlegroups.com
Hi Makul,

An _id field is required for the $group operation. If you want to remove the _id field after grouping, an extra $project would be the best way to do so.

Regards,
Stephen 

Asya Kamsky

unread,
Jun 16, 2014, 5:03:17 AM6/16/14
to mongodb-user
Technically, when you are using $out you are writing to a new collection and an _id will generated by MongoDB if one is not already provided.



--
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/7ccd77d6-8e31-4201-9e92-9accb726afe9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages