I try to do the examples based on the dataset:
http://media.mongodb.org/zips.jsonso i try to match the state equals "LA",and group the total pop within the state,the shell is:
db.zips.aggregate({$match:{state:"LA"}},{$group:{_state:"$state",total:{$sum:"$pop"}}})
like the doc says,phrase one:match the "LA" state docs,and the sum the pop,and the get the error like post title:
Error: Printing Stack Trace
at printStackTrace (src/mongo/shell/utils.js:37:15)
at DBCollection.aggregate (src/mongo/shell/collection.js:897:9)
at (shell):1:9
Sun Nov 3 04:08:19.542 aggregate failed: {
"errmsg" : "exception: the group aggregate field '_state' must be defined as an expression inside an object",
"code" : 15951,
"ok" : 0
after that error,i remenber r that mysql group syntax, if i want to do that i need use similar sql:select * from zips group by state having state='LA'
but i am just wondering why i can use the db.zips.aggregate({$match:{state:"LA"}},{$group:{_state:"$state",total:{$sum:"$pop"}}})

to do my request like the example said