If an update operation with upsert: true results in an insert of a
document, then $setOnInsert assigns the specified values to the fields in
the document. If the update operation does not result in an insert,
$setOnInsert does nothing.
public setOnInsert ( mixed $value ) | ||
$value | mixed |
/** * Set the current field to the value if the document is inserted in an * upsert operation. * * If an update operation with upsert: true results in an insert of a * document, then $setOnInsert assigns the specified values to the fields in * the document. If the update operation does not result in an insert, * $setOnInsert does nothing. * * @see Expr::setOnInsert() * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ * @param mixed $value * @return self */ public function setOnInsert($value) { $this->expr->setOnInsert($value); return $this; }
/** * 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 $setOnInsert operator is used. * * @see Expr::setOnInsert() * @see http://docs.mongodb.org/manual/reference/operator/set/ * @param mixed $value * @param boolean $atomic * @return self */ public function setOnInsert($value, $atomic = true) { $this->expr->setOnInsert($value, $atomic && $this->query['type'] !== Query::TYPE_INSERT); return $this; }