Hi @Dilip_Rajkumar ,
I since the scheduled time is done via a cron expression I don’t see how inserts should affect a schedule as long as the schedule make sense business wise (eg. After the 24h of inserted daily data).
The insert times should effect the date filtering inside the function to make sure you are scanning correct ranges of data. Mongodb does allow time alignment by using timezone in your query operators.
Now regarding the $max and $min, it sounds like the should be applied on a field like “$equity” or “$time” to get the max value or time per day, but you apply it to a static 1, which does not make sense to me… Can you elaborate.
I have to say that grouping on a new _id does not make sense as well. The _id in a group should be some meaningful expression , like a day date or null if you want to find min and max for the entire date range filter…
Now additionally please note that you can use a $merge stage in the end to write the output to the report collection rather than doing a loop of insertOne. This will probably be more efficient.
Let me know what are you current hazards.
Thanks
Pavel