Saturday 15 March 2014

mongodb - Mongo: Using $dayOfWeek in a $match clause when query has also a $groupy -


I have a Mongo document in which some registers are stored with a date, for example in a very simple way : "Vehicle ID": "Vehicle 4", "Telemetry date": ISOAD ("2013-06-22 Titi: 00: 00Z"), "AlarmTotal": 9} {"Vehicle ID": "Vehicle ID" "," Telemetry Date ": ISOAD (" 2013-06-20 -05: 00: 00Z ")," AlarmTotal ": 2}

I need to create a group by VHHIILID Alarm total. Still, there is no option to exclude the weekend (Saturday, Sunday).

I am not getting the answer to this question with Mongo. My inquiry works well without leaving the weekend:

  {"total": "telemetry chukra", "pipeline": [{"$ match": {"telemetryDate ": {" $ Gte ": {" $ date ": {2013-06-20T05: 00: 00.000Z}}," $ lte ": {" $ date ":" 2013-06-24 to 05: 00: ("$ Sum": "$ alarmsTotal"}}}}}   

I need to exclude those values ​​where the Mongo operator is $ day off wake 1 (Sunday) and 7 (Sunday). I tried through many questions, one of them is logical:

  {"total": "telemetry chukra", "pipeline": [{"$ match": {"telemetryDate ": {" $ Gte ": {" $ date ": {2013-06-20T05: 00: 00.000Z}}," $ lte ": {" $ date ":" 2013-06-24 to 05: 00: 00,000Z "}", "{\" $ DayOfWeek \ ": \" $ telemetryDate \ "}: {" $ in ": [2,3,4,5,6]}}}, {" $ group ": {"_id": {"VehicleId": "$ vehicleId"}, "alarm": {"$ sum": "$ alarmsTotal"}}}]}   

I think My real problem is basically that in the form of telemetry date in a day's variable, a $ de ophiak opera on a non-gruppy variables It is not known how to store Shan, I can compare it with $ in operator.

Thank you for reading and thanks for getting some guidance:) To do this really Very simple - you can use the $ project to create new fields that are not present in the original document - you can calculate the new values ​​or you can calculate the different values ​​as the conditional form S You can project.

What you need to do in the project phase:

  {you} "$": {"vehicle id": 1, "telemetry date": 1, AlarmTotal ": 1," Warmed Alarm ": {" $ cond ": [{" $ or ": [{" $ eq ": [" $ DayOfWeek ":" $ telemetryDate "}, 1]}, {" $ eq ": [[" $ DayOfWeek ":" $ telemetryDate "}, 7]}], 0," $ alarmsTotal "]}}} The above said:" All three areas Pass, but also calculate a new ground alarm such as: ... " 

The actual expression should be in the" English "rule:

  if the telemetry date 1 Dr Equivalent to the amount or '$ dayOfWeek` of telemetry date is equal to $ 7, then $ `project` value 0 as' Alarm Wi-vayyas ELSE '` $ AlarmsTotal` value `alarm wackage'   `$ Project` as  

No comments:

Post a Comment