#StackBounty: #java #mongodb #timezone Group by day and get last seven days data with respect to time zone in MongoDB

Bounty: 50

I have lot of document that look like this.

  "_id" : ObjectId("5bcf7d670a31a41b382823e2"), 
  "score" : 75

My backend language is java.
I use _id field to filter data by date.

I have a java method which give me Object_id with respect to timezone.

public static ObjectId getObjectId(String date, String fromTimeZone) {
  SimpleDateFormat formatterFrom = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  return new ObjectId(Long.toHexString(formatterFrom.parse(date).getTime() / 1000L) + "0000000000000000");

fromTimeZone could be something like .

Europe/London etc.

Now i would like to add some charts on my application dashboard. so i need last 7 days data like this.

{date: Nov-01, score:75}
{date: Nov-02, score:75}
{date: Nov-03, score:75}
{date: Nov-04, score:75}
{date: Nov-05, score:75}
{date: Nov-06, score:75}
{date: Nov-07, score:75}

Since lot of users use different time zone, I really dont have any idea how to do that.

help please.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.