Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to match for a certain day using a timestamp in MongoDB
    primarykey
    data
    text
    <p>Using example doc</p> <pre><code>{ "_id": { "$oid": "527339384bb8d32905f000853" }, "format": "flat1", "aggregation": "raw", "vm_id": "10101010", "hostname": "foo.example.com", "fooid": "100822", "ts": { "$date": "2013-11-01T05:00:23.000Z" }, "cpu_nanoseconds": 1410576880000000, "disk_usage": 20069460, "interface_public_rx_packets": 35771474, "interface_public_rx_bytes": 6023191691, "interface_public_rx_errors": 0, "interface_public_rx_drop": 0, "interface_public_tx_packets": 26004483, "interface_public_tx_bytes": 37293536055, "interface_public_tx_errors": 0, "interface_public_tx_drop": 0, "interface_private_rx_packets": 846833, "interface_private_rx_bytes": 63898435, "interface_private_rx_errors": 0, "interface_private_rx_drop": 0, "interface_private_tx_packets": 39, "interface_private_tx_bytes": 1638, "interface_private_tx_errors": 0, "interface_private_tx_drop": 0, "disk_primary_read_requests": 3280869, "disk_primary_read_bytes": 39818978304, "disk_primary_write_requests": 40331710, "disk_primary_write_bytes": 685420728320, "disk_swap_read_requests": 32, "disk_swap_read_bytes": 823808, "disk_swap_write_requests": 16, "disk_swap_write_bytes": 253952, "vcpu_nanoseconds_0": 470437920000000, "vcpu_nanoseconds_1": 344849460000000, "vcpu_nanoseconds_2": 342793890000000, "max_vcpus": 3} </code></pre> <p>I have the following query that groups information by day:</p> <pre><code>[ { "$match" : { "vm_id" : "1111223"}}, { "$group" : { "_id" : { "$dayOfMonth" : "$ts"}, "month" : { "$first" : { "$month" : "$ts"}}, "year" : { "$first" : { "$year" : "$ts"}}, "vm_id" : { "$first" : "$vm_id"}, "max_public_tx" : { "$max" : "$interface_public_tx_bytes"}, "public_tx_total" : { "$sum" : "$interface_public_tx_bytes"}, "public_rx_total" : { "$sum" : "$interface_public_rx_bytes"}, "private_tx_total" : { "$sum" : "$interface_private_tx_bytes"}, "private_rx_total" : { "$sum" : "$interface_private_rx_bytes"}, "count" : { "$sum" : 1}} }, { "$sort" : { "_id" : 1}} ] </code></pre> <p>So now I want to reduce it to hours for a particular day. I thought all I needed was to change the _id and add another item to $match such as {{"$dayOfMonth" : "$ts"} :1} for the first day of the month but MongoDb hated that some much it hung my IDE. What would be the proper $match query?</p> <p>The query I'm working on currently:</p> <pre><code>[ { "$match" : { "vm_id" : "1111223",{ "$dayOfMonth" : "$ts"}: 1 }}, { "$group" : { "_id" : { "$hour" : "$ts"}, "day" : {"$first" : {"$dayOfMonth" : "$ts"}}, "month" : { "$first" : { "$month" : "$ts"}}, "year" : { "$first" : { "$year" : "$ts"}}, "vm_id" : { "$first" : "$vm_id"}, "max_public_tx" : { "$max" : "$interface_public_tx_bytes"}, "public_tx_total" : { "$sum" : "$interface_public_tx_bytes"}, "public_rx_total" : { "$sum" : "$interface_public_rx_bytes"}, "private_tx_total" : { "$sum" : "$interface_private_tx_bytes"}, "private_rx_total" : { "$sum" : "$interface_private_rx_bytes"}, "count" : { "$sum" : 1}} }, { "$sort" : { "_id" : 1}} ] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload