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

set() public method

This is only relevant for insert, update, or findAndUpdate queries. For update and findAndUpdate queries, the $atomic parameter will determine whether or not a $set operator is used.
See also: Builder::set()
See also: http://docs.mongodb.org/manual/reference/operator/set/
public set ( mixed $value, boolean $atomic = true )
$value mixed
$atomic boolean
    public function set($value, $atomic = true)
    {
        $this->requiresCurrentField();
        if ($atomic) {
            $this->newObj['$set'][$this->currentField] = $value;
            return $this;
        }
        if (strpos($this->currentField, '.') === false) {
            $this->newObj[$this->currentField] = $value;
            return $this;
        }
        $keys = explode('.', $this->currentField);
        $current =& $this->newObj;
        foreach ($keys as $key) {
            $current =& $current[$key];
        }
        $current = $value;
        return $this;
    }

Usage Example

示例#1
0
 /**
  * Set the current field to a value.
  *
  * This is only relevant for insert, update, or findAndUpdate queries. For
  * update and findAndUpdate queries, the $atomic parameter will determine
  * whether or not a $set operator is used.
  *
  * @see Expr::set()
  * @see http://docs.mongodb.org/manual/reference/operator/set/
  * @param mixed $value
  * @param boolean $atomic
  * @return self
  */
 public function set($value, $atomic = true)
 {
     $this->expr->set($value, $atomic && $this->query['type'] !== Query::TYPE_INSERT);
     return $this;
 }