public function findAndModify($collectionName, $condition = [], $update = [], $options = [])
    {
        $document = array_merge(['findAndModify' => $collectionName], $options);

        if (!empty($condition)) {
            $options['query'] = $this->buildCondition($condition);
        }

        if (!empty($update)) {
            $options['update'] = $update;
        }

        if (isset($options['fields'])) {
            $options['fields'] = $this->buildSelectFields($options['fields']);
        }

        if (isset($options['sort'])) {
            $options['sort'] = $this->buildSortFields($options['sort']);
        }

        foreach (['fields', 'query', 'sort', 'update'] as $name) {
            if (isset($options[$name])) {
                $document[$name] = (object) $options[$name];
            }
        }

        return $document;
    }
public function findAndModify($collectionName, $condition = [], $update = [], $options = [])
    {
        $document = array_merge(['findAndModify' => $collectionName], $options);

        if (!empty($condition)) {
            $options['query'] = $this->buildCondition($condition);
        }

        if (!empty($update)) {
            $options['update'] = $update;
        }

        if (isset($options['fields'])) {
            $options['fields'] = $this->buildSelectFields($options['fields']);
        }

        if (isset($options['sort'])) {
            $options['sort'] = $this->buildSortFields($options['sort']);
        }

        foreach (['fields', 'query', 'sort', 'update'] as $name) {
            if (isset($options[$name])) {
                $document[$name] = (object) $options[$name];
            }
        }

        return $document;
    }
public function findAndModify ( $ collectionName , $ condition = [ ] , $ update = [ ] , $ options = [ ] ) { $ document = array_merge ( [ 'findAndModify' => $ collectionName ] , $ options ) ; if ( ! empty ( $ condition ) ) { $ options [ 'query' ] = $ this -> buildCondition ( $ condition ) ; } if ( ! empty ( $ update ) ) { $ options [ 'update' ] = $ update ; } if ( isset ( $ options [ 'fields' ] ) ) { $ options [ 'fields' ] = $ this -> buildSelectFields ( $ options [ 'fields' ] ) ; } if ( isset ( $ options [ 'sort' ] ) ) { $ options [ 'sort' ] = $ this -> buildSortFields ( $ options [ 'sort' ] ) ; } foreach ( [ 'fields' , 'query' , 'sort' , 'update' ] as $ name ) { if ( isset ( $ options [ $ name ] ) ) { $ document [ $ name ] = ( object ) $ options [ $ name ] ; } } return $ document ; }
Generates 'find and modify' command.
@param string $collectionName collection name
@param array $condition filter condition
@param array $update update criteria
@param array $options list of options in format: optionName => optionValue.
@return array command document.
Generates find and modify command .