Пример #1
0
 public function testNormalize_Complex()
 {
     $subExpression = new Expression();
     $subExpression->mod('$fieldName', 2);
     $expression = Expression::normalize(array('field1' => 1, 'field2' => $subExpression, 'field3' => function ($expression) {
         $expression->add('$fieldName', 5);
     }, 'field4' => array('subField41' => 1, 'subField42' => $subExpression, 'subField43' => function ($expression) {
         $expression->add('$fieldName', 5);
     }, 'subField44' => array('subField441' => 1, 'subField442' => $subExpression, 'subField443' => function ($expression) {
         $expression->add('$fieldName', 5);
     }))));
     $this->assertEquals(array('field1' => 1, 'field2' => array('$mod' => array('$fieldName', 2)), 'field3' => array('$add' => array('$fieldName', 5)), 'field4' => array('subField41' => 1, 'subField42' => array('$mod' => array('$fieldName', 2)), 'subField43' => array('$add' => array('$fieldName', 5)), 'subField44' => array('subField441' => 1, 'subField442' => array('$mod' => array('$fieldName', 2)), 'subField443' => array('$add' => array('$fieldName', 5))))), $expression);
 }
Пример #2
0
 /**
  * Returns an array of all values that result from applying an expression
  * to each document in a group of documents that share the same group by key.
  *
  * @link http://docs.mongodb.org/manual/reference/operator/aggregation/push
  *
  * @param string $field
  * @param literal|callable|\Sokil\Mongo\Pipeline\Expression $expression Expression
  * @return \Sokil\Mongo\Pipeline\GroupStage
  */
 public function push($field, $expression)
 {
     $this->stage[$field]['$push'] = Expression::normalize($expression);
     return $this;
 }