Sokil\Mongo\Expression::where PHP Method

where() public method

Return a expression
public where ( $field, $value ) : Cursor | Expression
return Cursor | Expression
    public function where($field, $value)
    {
        if (!isset($this->_expression[$field]) || !is_array($value) || !is_array($this->_expression[$field])) {
            $this->_expression[$field] = $value;
        } else {
            $this->_expression[$field] = array_merge_recursive($this->_expression[$field], $value);
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Filter by id
  *
  * @param string|\MongoId $id id of document
  * @return \Sokil\Mongo\Cursor
  */
 public function byId($id)
 {
     if ($id instanceof \MongoId) {
         $this->expression->where('_id', $id);
     } else {
         try {
             $this->expression->where('_id', new \MongoId($id));
         } catch (\MongoException $e) {
             $this->expression->where('_id', $id);
         }
     }
     return $this;
 }
All Usage Examples Of Sokil\Mongo\Expression::where