Doctrine\MongoDB\Query\Expr::currentDate PHP Method

currentDate() public method

Sets the value of the current field to the current date, either as a date or a timestamp.
See also: Builder::currentDate()
See also: http://docs.mongodb.org/manual/reference/operator/update/currentDate/
public currentDate ( string $type = 'date' )
$type string
    public function currentDate($type = 'date')
    {
        if (!in_array($type, ['date', 'timestamp'])) {
            throw new InvalidArgumentException('Type for currentDate operator must be date or timestamp.');
        }
        $this->requiresCurrentField();
        $this->newObj['$currentDate'][$this->currentField]['$type'] = $type;
        return $this;
    }

Usage Example

示例#1
0
 /**
  * Sets the value of the current field to the current date, either as a date or a timestamp.
  *
  * @see Expr::currentDate()
  * @see http://docs.mongodb.org/manual/reference/operator/currentDate/
  * @param string $type
  * @return self
  */
 public function currentDate($type = 'date')
 {
     $this->expr->currentDate($type);
     return $this;
 }