This is the first time I am using mongo for a meteor project, which is to help collaborate a group of users to read the holy scriptures. The data structure for the collection looks as follows:
//collection is named as 'logs'
[
{
_id: someObjectId,
startPage: 1,
finishPage: 4,
status: 'in progress',
userId: someUserId1
},
{
_id: someObjectId,
startPage: 5,
finishPage: 10,
status: 'done',
userId: someUserId2
}
//.... and so on and normally two users wont read the same page.
]
I am trying to figure out the following:
- Total Pages "Done"
- Total Pages "In Progress"
- Next available Page
- Missing Pages
Now due to my limited knowledge of mongo I'm stuck at this point. I have been looking at various solutions but not sure which one would be the right fit:
- Aggregation (but I'm unclear as to how I would achieve the required data)
- MapReduce (should this be used every time when a new log is added or MapReduce is only meant to run as a batch job)
- Create a new separate collection that would hold all the tracking data and update it every time a log is either added or updated
e.g.
[
{
page: 1,
inProgress: 0, //users would normally not read the same page twice but they may
done: 1
},
{
page: 2,
inProgress: 1, //users would normally not read the same page twice but they may
done: 0
}
]
I would be really grateful if somebody could provide some insight into this and preferred way of doing it. It may be obvious but I'm finding it a bit hard. Thanks.