Im a MongoDB noob so please dont judge me if my question is stupid:P Im trying to get some results from MongoDB to create a table that would show percentage statistics of how much do i play a certain game per day of week (all games together per day = 100%). This is my JSON import for the database:
[
{"title":"GTA","date":"2017-11-13"},
{"title":"GTA","date":"2017-11-13"},
{"title":"BattleField","date":"2017-11-13"},
{"title":"BattleField","date":"2017-11-13"},
{"title":"BattleField","date":"2017-11-14"}
]
Ive written an aggregation that grouped the results by days and counted the total amount of times a game has been played per each day…:
db.games.aggregate([
{ $project: { _id: 0, date : { $dayOfWeek: "$date" }, "title":1} },
{ $group: { _id: {title: "$title", date: "$date"}, total: {$sum: 1} } },
{ $group: { _id: "$_id.date", types: {$addToSet: {title:"$_id.title", total: "$total"} } } }
])
…and this is what i got from MongoDB now:
/* 1 */
{
"_id" : 3,
"types" : [
{
"title" : "BattleField",
"total" : 1.0
}
]
},
/* 2 */
{
"_id" : 2,
"types" : [
{
"title" : "GTA",
"total" : 2.0
},
{
"title" : "BattleField",
"total" : 2.0
}
]
}
what i need to get is a table that would look like this:
Monday Tuesday
GTA 50,00% 0%
BattleField 50,00% 100%
Could you please advise me how can i get such percentage results from Mongo?