0

I use node js technology, write backend in express js and database in mongoose

I'm having a "User" Model as follows:

{_id: ObjectId,
name: string,
score: number,
timeStamp: Date}

For example, if a user answers a question, I will find and update that user's "score" field.

But I don't know get the most active users by day, week, and month, yesterday, last week, and last month, based on activity scoring criteria for each time period.

For example, to be the most active user today, I would have to calculate the change in each user's field score from the beginning of the day to the current time

Help me and thanks a million!

Is it necessary to use cronjob and create fields like "today's score" field, and "this month's score" field, then every time the "score" field changes, it will be updated to "today's score" field, "this month's score" field?

  • How about a new field, for example `"answers"` that is an array with each user's answers ... maybe using objects like `{"questionId": 1234, "score": 10, "timestamp": new Date()}`. You could then perform aggregation queries over any time period, or question, etc. – rickhg12hs Aug 31 '23 at 04:24

0 Answers0