How do I group by _id?
===

    conn = Mongo::Connection.new
    db   = conn['foobar_development']

    cmd = {
      aggregate: 'live_daily_stats',
      pipeline: [
        # { '$match' => { :_id => "20120725/foobar/song/custom-cred" } },
        { '$project' => {
          :visits => 1,
        } },
        { '$unwind' => '$visits' },
        # { '$group' => {
        #   :_id => '$_id'
        # } },
        { '$match' => { 'visits.minute' => { '$gt' => 224 } } },
        { '$sort' => { 'visits.minute' => 1 } },
        # { '$group' => { :_id => '$_id' } },
      ]
    }

    res = db.command(cmd)['result']

returns:

    [
        [0] {
               "_id" => "20120725/foobar/song/custom-cred",
            "visits" => {
                                              "country_name" => "UK",
                               "iso_two_letter_country_code" => "UK",
                                                   "referer" => "http://localhost:3000/cfazzini/songs/custom-cred",
                                                    "minute" => 251,
                                                  "token_id" => "134318948211lzyqexgo"
            }
        },
        [1] {
               "_id" => "20120725/foobar/song/custom-cred",
            "visits" => {
                                              "country_name" => "UK",
                               "iso_two_letter_country_code" => "UK",
                                                   "referer" => "http://localhost:3000/cfazzini/songs/custom-cred",
                                                    "minute" => 1118,
                                                  "token_id" => "134324148411hsrxvakn"
            }
        },
        [2] {
               "_id" => "20120725/foobar/song/test-pg3-long-title-here-test-lorem-ipsum-dolor-lo",
            "visits" => {
                                              "country_name" => "UK",
                               "iso_two_letter_country_code" => "UK",
                                                   "referer" => "http://localhost:3000/",
                                                    "minute" => 1121,
                                                  "token_id" => "13432416893tlfsmmgh"
            }
        },
        [3] {
               "_id" => "20120725/foobar/song/custom-cred",
            "visits" => {
                                              "country_name" => "UK",
                               "iso_two_letter_country_code" => "UK",
                                                   "referer" => "http://localhost:3000/",
                                                    "minute" => 1121,
                                                  "token_id" => "134324169011hmtkxrgt"
            }
        }
    ]

Second, how can I run the same command using a rails model, without having to define `conn` and `db`?