// Projects the sum of the fields where
// I can access in template
$group: {
'_id': this.userId,
'hours': {
$sum: '$hours'
}
}
}, {
$project: {
hours: '$hours',
}
db.users.aggregate(
[
{ $project : { month : { $month : "$createdAt" } } } ,
{ $group : { _id : {month:"$month"} , number : { $sum : 1 } } },
{ $sort : { "_id.month" : 1 } }
]
)
[{ $project: { month_report: { $month: "$createdAt" } } }, { $group: { _id: { month_report: "$month_report" }, number: { $sum: "$hours" //this part, how do I properly reference my 'hours' field? } } }]
{ $project : { month_report: "$createdAt" , hours : 1 } }
for the first stage.
also for debugging pipelines, it's really useful to just run a portion of the pipeline and look at the output. for example you coudl run:
> db.foo.aggregate( [ { $project : { month_report: "$createdAt" } } ] )
and you will see there is no hours value in the output -- and know what to adjust then.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d243e682-314a-42af-aa11-87df233463a0%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
Where will getting the user context for in the grouping?
The only part missing at the moment is getting the monthly summation specific to the user. Meteor allows accessing current logged in user as `this.userId`.
Where will getting the user context for in the grouping?
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d6f48c1a-5408-4487-a1c1-850fc7d5c322%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
$project: { _id: 0, userId: this.userId, month: '$_id', hours: '$hours' }Exception from sub reportMonthly id p5D4Qqq6kKZhcpqzc MongoError: exception: FieldPath 'n74SEjEBHjAoSDuqG' doesn't start with $ $project: { _id: 0, userId: {
$literal: this.userId
}, month: '$_id', hours: '$hours' }