How To Use Group By In MongoDB

Praveen Singh         No comments

We all use GROUP BY clause in Sql platforms (like SQL SERVER) extensively. It's simple..

SELECT * FROM (TABLE)
WHERE (CONDITION)
GROUP BY (COLUMN NAME)

I know it's a bit queasy feeling when we have to go out of our comfort zone and do the same thing in a different platform.But it's also fun..

So, how to do it ??

I will explain each step with screenshot to get you the clear view of everything...

First , we will create a collection and insert some data into it..


To confirm, we have data in the collection :

db.product.find().pretty()



So, now we have data in the collection, we can use GROUP by using the below mentioned commands..


In the above screenshot, we are grouping data based on the type. Also, adding some more information using $addToSet ...

That's it !!!




Published by Praveen Singh

A blogger by passion.You can find me tucked in my bed and blogging on weekends when not roaming around. Besides blogging, I love music and you can find my songs on my fb page:PraveenUnplugged
.
Follow on Youtube : Videos On Latest Happenings |ThingsToKnow
.
Follow us Talend In Action

0 responses:

© 2015 Techie's House. Designed by Bloggertheme9