blue | 50,000000% |
red | 33,333333% |
yellow | 16,666667% |
I have managed to calculate percentages, but I still have a step missisng ...
I need to calculate the total number of documents (in yellow) inside the [], inside the "aggregation" operation.
[
{ "$group": { "_id": {"colour": "$colour"}, "count": { "$sum": 1 }}},
{ "$project": {
"count": 1,
"percentage": {
"$concat": [ { "$substr": [ { "$multiply": [ { "$divide": [ "$count", 6 ] }, 100 ] }, 0,4 ] }, "", "%" ]}
}
}
]
That is what is supposed to do, but I can not do it. because where I am working, I can only type "aggregation" operations:
var total = db.mycollection.count ()
[
{ "$group": { "_id": {"colour": "$colour"}, "count": { "$sum": 1 }}},
{ "$project": {
"count": 1,
"percentage": {
"$concat": [ { "$substr": [ { "$multiply": [ { "$divide": [ "$count", total ] }, 100 ] }, 0,4 ] }, "", "%" ]}
}
}
]
So, I would like to know whether I can calculate the TOTAL inside the []
Thanks!
--
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 http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/f8a2d991-b672-4e01-8631-e45ba52b22f7%40googlegroups.com.