last day (16 days later) » 

10:27 AM
1
A: Mongodb Aggregate - Grouping by hour for today

ValijonEXPLANATION If we use $$NOW, we get current date. If you setup currDate, today, nextDay manually, MongoDB aggregation will limit desired values. Now, we calculate how many hours from today (yyyy-MM-dd 00:00:00) - currDate (yyyy-MM-dd 13:35:00) ~ 13 hours and with $range operator create array We...

 
can we use startDate and endDate from javascript variables?
 
Sure. Setup currDate, nextDay and today values
Make sure you have copy-paste last version of my code
 
Sure, thank you for helping me. Now I have last problem, it is getting the load of my Fitness. Like if my visit was from 10:00 to 12:30 I needed to show that at 10:00 1 visit, at 11:00 1 visit, and at 12:00 also 1 visit. How can I reach this logic?
 
Can you setup MongoPlayground and click "Share" button. I need to see what is your input data
 
mongoplayground.net/p/o5thxBQPYEb there I need to get visit for 10, 11 and 12 hours. So it gives me load of people of my Fitness because person was in my fitness for 3 hours
 
10:27 AM
Isn't correct output result? mongoplayground.net/p/irtKhgUQJr5
 
It is but why it is 2 visits for 2020-01-17T10:00:00Z? It shoulb be 1 visit. We can ignore subvisits.
 
For 10:00 - 11:00
"from": ISODate("2020-01-17T10:23:27.646Z"),
"to": ISODate("2020-01-17T10:30:28.760Z")
meets this criteria
"from": ISODate("2020-01-17T10:30:29.760Z"),
"to": ISODate("2020-01-17T12:23:28.760Z"),
this is also
 
Yes you are right, Before there was not counting visits for 3 hours. Now it is
It was my mistake
 
or you need to no exceed 10:00 - 11:00 ?
 
I need
In examples before there was not countings for 3 hours
Now it counts
 
10:31 AM
nice
 
It is exactly what I needed
 
cool :D
 
Thank you very much
 
you are welcome
 
How can I learn these techniques by myself?
 
10:32 AM
practise :D. It costs me 2 hours thinking :D
 
It is really interesting to create such difficult repots
 
yeah
 
Thank you
It costed me 1,5 day
 
not bad :D
 
Till I posted in stackoverflow
=D
 
10:33 AM
next time you will get more easier
 
I hope
Just I was SQL Master
 
in MySQL is it possible?
to get such result?
 
There everything is different
Yes it is
 
with select or creating procedure?
you can create in SQL 00:00, 01:00, 02:00 ... ?
from 1 entry
 
Yes
With select
 
10:36 AM
the key of this solution: $ange operator, I don't know how to create multiple entrance from 1 field
* $range
 
Mongodb you mean&
?
 
yeah
 
ok
Where are you from?
 
in SQL how would you do it? curious
spain
 
SELECT DATE '2019-03-01' + ( LEVEL - 1 ) * INTERVAL '30' MINUTE AS dates
FROM DUAL
CONNECT BY DATE '2019-03-01' + ( LEVEL - 1 ) * INTERVAL '30' MINUTE <= DATE '2019-04-01';
This is just an example how to create 00:00, 01:00, 02:00 ...
So to get the same result we need too much work =D
 
10:48 AM
LOL, yeah you are right. Didn't know SQL allows such things... Thanks fro info
 
Thank you too
 
Good luck then, bye!
 
One more question
 
tell me
 
When I don't have any records for current date range it returns me nothing, can I avoid retting nothing?
*getting
 
10:51 AM
Give me example
 
Just remove $match stage after $adFields
 
Won't it cost much than previous query?
I mean if I have millions of rows
 
11:13 AM
What does it give?
 
You said: When I don't have any records for current date range it returns me nothing, can I avoid getting nothing?
 
Oh yes, I remember
 
I've updated my answer. Anything else?
 
Also one question, is it important to have nextDay variable?, I mean can we avoid third variable?
 
It's for limitation use
ofcourse you can avoid it
 
11:23 AM
How?
 
Thank you!
That is all
 
nice, For the further help, comment in my answer. Good luck and nice to meet you
 
ok
nice to meet you too
 

  last day (16 days later) »