Group by time interval and offset interval

Hi guys,

I want to query the data based on time, so i tried group by time(15mins) with match followed by group query.
Group by time: 15 mins

{$group: {_id: {"date": {"$subtract": [{"$toLong": {"$toDate": "$timeStamp"}}, {"$mod": [{"$toLong": {"$toDate": "$timeStamp"}},900000]}]}},value:{$avg:{"$divide": ["$rvalue",1000]}}}}

This gives me timeStamp with millisec and avg value.
But now I want a query where group by time and offset…query similar to influx group by time(time_intervel,offset_interval)
example influx query:

SELECT MEAN("water_level") FROM "h2o_feet" 
WHERE "location"='coyote_creek' 
AND time >= '2015-08-18T00:06:00Z' 
AND time <= '2015-08-18T00:54:00Z' 
GROUP BY time(18m,6m)

Hi @Bukka_Dinakar and welcome to the MongoDB community forum

As we are unfamiliar with Influx, it would be helpful in understanding and replicating in local environment, if you could share the following information

  1. A sample document from the collection
  2. The desired output example for the aggregation query.
  3. The aggregation query you have tried.
  4. The MongoDB version you are using.

Best Regards

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.