public function addToSet($name, $value, $emulate = null)
  {
    $name = $this->get_field_name($name);
    if(isset($this->_operations['$addToSet'][$name]))
    {
      if( ! isset($this->_operations['$addToSet'][$name]['$each']))
      {
        $this->_operations['$addToSet'][$name] = array('$each' => array($this->_operations['$addToSet'][$name]));
      }
      if(isset($value['$each']))
      {
        foreach($value['$each'] as $val)
        {
          $this->_operations['$addToSet'][$name]['$each'][] = $val;
        }
      }
      else
      {
        $this->_operations['$addToSet'][$name]['$each'][] = $value;
      }
    }
    else
    {
      $this->_operations['$addToSet'][$name] = $value;
    }
    if ($emulate === FALSE || ($emulate === null && $this->_emulate === FALSE))
    {
      return $this->_set_dirty($name);
    }
    else
    {
      $ref = & $this->get_field_reference($name, TRUE);
      if ($ref === null)
      {
        $ref = array($value);
      }
      else
      {
        if (!is_array($ref)) throw new Exception("Value '$name' cannot be set as an array"); // $ref = array($ref);
        if (!in_array($value, $ref, TRUE))
        {
          array_push($ref, $value);
        }
      }
      return $this;
    }
  }