Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Support use Group to sum array of object.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tom Vo  
View profile  
 More options Sep 12 2012, 6:19 am
From: Tom Vo <tom...@nexcel.vn>
Date: Wed, 12 Sep 2012 03:19:37 -0700 (PDT)
Local: Wed, Sep 12 2012 6:19 am
Subject: Support use Group to sum array of object.

Dear all
My collections which have key is a array object.
I need sum total as SQL statement:
                   *Select Line_Items.Name , Sum(Line_Items.Quantity) from
Orders group by Line_Items.Name*
Could I use group to sum data instead of map/reduce?
Please help me for this case ?

Thanks

My data samples

db.Orders.find()
{
        "_id" : ObjectId("505057cbe415556238661561"),
        "BuyerName" : "Lukas",
        "Line_Items" : [
                {
                        "Name" : "2012 Accord SeDan",
                        "Pricing" : 20,
                        "Quantity" : 1
                },
                {
                        "ProductID" : ObjectId("50504b36e41555623866155c"),
                        "Name" : "2012 Accord Coupe",
                        "Pricing" : 15,
                        "Quantity" : 2
                }
        ],
        "IssueDate" : ISODate("2012-03-08T00:00:00Z"),
         "Total" : 50

}

,

{
        "_id" : ObjectId("505057cbe415556238661560"),
        "BuyerName" : "Bobby",
        "Line_Items" : [
                {
                        "Name" : "2012 Accord SeDan",
                        "Pricing" : 15,
                        "Quantity" : 1
                }
        ],
        "IssueDate" : ISODate("2012-02-08T00:00:00Z"),
        "Total" : 15

}

Thanks and Regards.

Tom Vo


 
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.
Tom Vo  
View profile  
 More options Sep 12 2012, 10:05 pm
From: Tom Vo <tom...@nexcel.vn>
Date: Wed, 12 Sep 2012 19:05:58 -0700 (PDT)
Local: Wed, Sep 12 2012 10:05 pm
Subject: Re: Support use Group to sum array of object.

Dear all
Have Mongodb support sum/avg key in array of Object by use Aggregation
Group/Map Reduce yet?

Best regards.


 
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.
Stephen Steneker  
View profile  
 More options Sep 18 2012, 12:48 am
From: Stephen Steneker <stephen.stene...@10gen.com>
Date: Mon, 17 Sep 2012 21:48:14 -0700 (PDT)
Local: Tues, Sep 18 2012 12:48 am
Subject: Re: Support use Group to sum array of object.

> My collections which have key is a array object.
> I need sum total as SQL statement:
>                    *Select Line_Items.Name , Sum(Line_Items.Quantity)
> from Orders group by Line_Items.Name*
> Could I use group to sum data instead of map/reduce?

Hi Tom,

You could use the Aggregation Framework in MongoDB 2.2 to sum the data by
name:

db.Orders.aggregate(
  { $unwind: "$Line_Items" },
  { $group : {
 _id: "$Line_Items.Name",
 Quantity: { $sum: "$Line_Items.Quantity"}
  }}
)

There are a few limitations to be aware of, in particular that the output
from the Aggregation Framework is limited to the maximum BSON document size
(16Mb): http://docs.mongodb.org/manual/applications/aggregation/#limitations.

You may also want to start your aggregation with an indexed $match to limit
the range of documents to aggregate.

> Have Mongodb support sum/avg key in array of Object by use Aggregation

Group/Map Reduce yet?

The new aggregation framework includes a number of mathematical functions
such as $sum, $avg, $min, and $max:
 http://docs.mongodb.org/manual/reference/aggregation/#arithmetic-oper...

Cheers,
Stephen


 
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.
Tom Vo  
View profile  
 More options Sep 18 2012, 1:34 am
From: Tom Vo <tom...@nexcel.vn>
Date: Tue, 18 Sep 2012 12:34:25 +0700
Local: Tues, Sep 18 2012 1:34 am
Subject: Re: [mongodb-user] Re: Support use Group to sum array of object.

Hi Stephen
Thanks for your suggestion .

On Tue, Sep 18, 2012 at 11:48 AM, Stephen Steneker <

--

Thanks and Best Regards
--------------------------------------------------------------------------- ----------------------------------
*Vo Tan Hau* (*TOM*)
*Senior Database Administrator*
NEXCEL SOLUTIONS LTD
*SMS Tower,Lot 40, Quang Trung Software City, District 12, HCMC, Vietnam.*
*Tel*:+84-8-37154278 *-* *Fax*:+84-8-37154279 www.nexcel.vn*
Messenger *(*Skype+Yahoo+Live*): Vohau2002


 
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.
End of messages
« Back to Discussions Older topic »