From: kirill kazachenko <cih.exe...@gmail.com>
Date: Wed, 14 Nov 2012 22:46:06 -0800 (PST)
Local: Thurs, Nov 15 2012 1:46 am
Subject: Re: Aggregation framework. Group by sub-document fields
WOW! Really thanks! It's that what i was need!
> db.sessions.aggregate(
{$project: {_id:1,events:1}},
{$unwind:"$events"}, {$group: {_id:"$events.name", count: {$sum:1}}}) made:
{
}
среда, 14 ноября 2012 г., 20:12:45 UTC+3 пользователь Stephen Lee написал:
> Hi Kirill,
> Check out the $unwind operator > Before $unwind:
> {
> After $unwind:
> { a:1,b:2 },
> After you include the $unwind in your pipeline, add the $group operation > -Stephen
> On Tuesday, November 13, 2012 4:13:35 PM UTC-5, kirill kazachenko wrote:
>> Hello, i have a question about grouping by sub elements.
>> i have next structure:
>> I'm need to extract and group all events by name with it's count, how can >> db.sessions.aggregate([{$group: {_id:"$events.name"}}])
>> i have response:
>> {
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||