Skip to content

implements $addToSet #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,28 @@ public function push($column, $value = null)

return $this->performUpdate($query);
}


/**
* Append one or more values to an array IF not exist in array.
*
* @param mixed $column
* @param mixed $value
* @return int
*/
public function addToSet($column, $value = null)
{
if (is_array($column))
{
$query = array('$addToSet' => $column);
}
else
{
$query = array('$addToSet' => array($column => $value));
}

return $this->performUpdate($query);
}

/**
* Remove one or more values from an array.
Expand Down