匹配和按日期分组

时间:2017-02-24 12:47:02

标签: php mongodb aggregation-framework

我有一个mysql查询,需要使用php executeCommand或executeQuery将最新版本的Driver \ Manager mongodb.so转换为mongodb。

$manager = new MongoDB\Driver\Manager("mongodb://".$_SERVER['HTTP_HOST'].":27017");
    $cond = [ 'created_time' => ['$gte' => '(NOW() - INTERVAL 10 DAY'], 'active' => 1 ];
    $command = new MongoDB\Driver\Command([
        'aggregate' => 'collection_name',
        'pipeline' => [
            ['$match' => $cond],
            ['$group' => ['_id' => '$created_time', 'total' => ['$sum' => '$_id']]],
        ],
        'cursor' => new stdClass,
    ]);
    $cursor = $manager->executeCommand('db_name', $command);
    $result = array();
    foreach ($cursor as $document) {
        $result[] = $document;
    }

到目前为止尝试的是:

@-webkit-keyframes anim {
      from {
        transform: perspective(600px) rotate3d(1, 0, 0, 90deg);
        -webkit-transform: perspective(600px) rotate3d(1, 0, 0, 90deg);
        animation-timing-function: ease-in;
        -webkit-animation-timing-function: ease-in;
      }

      to {
        transform: perspective(600px);
        -webkit-transform: perspective(600px);
      }
    }

    @keyframes anim {
      from {
        transform: perspective(100px) rotate3d(1, 0, 0, 90deg);
        -webkit-transform: perspective(600px) rotate3d(1, 0, 0, 90deg);
        animation-timing-function: ease-in;
        -webkit-animation-timing-function: ease-in;
      }

      to {
        transform: perspective(600px);
        -webkit-transform: perspective(600px);
      }
    }

    .anim {
        animation-duration : 10s;
        -webkit-animation-duration: 10s;
        animation-fill-mode: both;
        -webkit-animation-fill-mode: both;
        backface-visibility: visible !important;
        -webkit-backface-visibility: visible !important;
        animation-name: anim;
        -webkit-animation-name: anim;
    }

1 个答案:

答案 0 :(得分:0)

你很亲密。

使用以下内容更新您的$cond。休息看起来很好。

$date = new DateTime();
$date->sub(new DateInterval('P10D'));
$cond = [ 'created_time' => ['$gte' => $date], 'active' => 1 ];             

更新分组键_id以仅包含日期部分。

['$dateToString' => ['format' => "%Y-%m-%d", 'date' => '$created_time']]