[SERVER-9577] new deverloper question on usage of Aggregation Framework Created: 03/May/13  Updated: 24/Jun/13  Resolved: 06/May/13

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.4.0
Fix Version/s: None

Type: Question Priority: Minor - P4
Reporter: Craig Curtin Assignee: Linda Qin
Resolution: Done Votes: 0
Labels: aggregation
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB shell version: 2.4.1

Linux
-sh-3.2$ uname -a
Linux lltwe28088.lvt.us.ml.com 2.6.18-308.1.1.el5 #1 SMP Fri Feb 17 16:51:01 EST 2012 x86_64 x86_64 x86_64 GNU/Linux


Attachments: File Mongo Framework Aggregation Dev help.msg     Text File Mongo Framework Aggregation help.txt    
Issue Links:
Related
is related to SERVER-9604 Improve the error message if $last op... Closed
Participants:

 Description   

please see attached outlook email message.

let me know if you can't open or if this is not a good medium for you.

yep, i'm a n00b with Framework ... I've been through the online docs and I'm still doing something stupid.

Help!



 Comments   
Comment by Craig Curtin [ 06/May/13 ]

Linda,
Thanks ... I swear I tried this .....

ah, you know what is like ... I'm new and hacking around a bunch of things to make something work.

thanks for your help,

Craig

Comment by Linda Qin [ 06/May/13 ]

Hi Craig,

You got the "invalid operator" error message because you tried to use the $last operator in the _id field.

Per the documentation for the $last operator, you should use $last when the $group follows a $sort operation.

To get the latest free memory percentage for each group, you can use the aggregation operation like this:

db.RSgc.aggregate([
    // sort the documents by utime
    { $sort : { utime : 1 }},
    { $group : { 
        // group the documents by host and port
        _id : { myhost : "$host",
                myport : "$port", },
        // get the latest free memory percentage for each group
        freeMem : { $last : "$postFreePct" }
    }},
])

This will give you the following result:

{
	"result" : [
		{
			"_id" : {
				"myhost" : "mrsp6.mrisk.bankofamerica.com",
				"myport" : 4329
			},
			"freeMem" : 46.314380787037
		}
	],
	"ok" : 1
}

Regards,
Linda

Comment by Craig Curtin [ 04/May/13 ]

re-saved as text.

Thanks,
Craig

Comment by Eliot Horowitz (Inactive) [ 04/May/13 ]

Can you copy the content of the email as text?

Generated at Thu Feb 08 03:20:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.