public function push($fieldName, $value)
{
// prepasre to store
$value = Structure::prepareToStore($value);
// no $push operator found
if (!isset($this->operators['$push'])) {
$this->operators['$push'] = array();
}
// no field name found
if (!isset($this->operators['$push'][$fieldName])) {
$this->operators['$push'][$fieldName] = $value;
} else {
if (!is_array($this->operators['$push'][$fieldName]) || !isset($this->operators['$push'][$fieldName]['$each'])) {
$oldValue = $this->operators['$push'][$fieldName];
$this->operators['$push'][$fieldName] = array('$each' => array($oldValue, $value));
} else {
$this->operators['$push'][$fieldName]['$each'][] = $value;
}
}
return $this;
}