gehören kann ich nächste Dummy-Dataset haben:MongoDB Aggregation - Gruppe von Datumsbereichen, wo ein Dokument mehrere Bereiche
{"id": 1, "date": "2017-04-01", "total": 1}
{"id": 2, "date": "2017-04-03", "total": 2}
{"id": 3, "date": "2017-04-10", "total": 1}
{"id": 4, "date": "2017-04-11", "total": 1}
auch habe ich etwas fester Wert count_of_days
. Lassen Sie es gleich 5 (count_of_days = 5
)
ich als nächste Gruppen erstellen muß:
{"2017-04-01 + 5 days": count: 2, sum_of_total: 3}
{"2017-04-03 + 5 days": count: 1, sum_of_total: 2}
{"2017-04-10 + 5 days": count: 2, sum_of_total: 2}
{"2017-04-11 + 5 days": count: 1, sum_of_total: 1}
wo count
ist Anzahl der Dokumente, das Datumsfeld in Bereich ist [date; date + count_of_days]
so für Dokument mit id=1
wir solche Gruppe haben
{"2017-04-01 + 5 days": count: 2, sum_of_total: 3}
weil
doc 1 date
ist in Reichweite [2017-04-01; 2017-04-06 (+ 5 days)]
und
doc 2 date
2017-04-03
ist in Reichweite [2017-04-01; 2017-04-06 (+ 5 days)]
Wie kann ich tun dies mit aggregation framework
oder vielleicht Map/Reduce
?
das Hauptziel ist, die Produktivität und Rechengeschwindigkeit
sorry, aber ist nicht klar, was Sie zu fragen, versuchen, versuchen, Ihre Frage Refactoring. – leonziyo
@leonziyo Ich habe versucht, getan –
ist Ihr Datum ein String Datentyp oder Datum Datentyp? – leonziyo