public function document($value, $id = null, $update = false)
    {
        if (!$this->batch instanceof BatchCommand) {
                        throw new exceptions\RuntimeException("Cannot add a new document to an external BatchCommandInterface");
        }

        $this->finalizeCurrentCommand();


        if (is_array($value)) {
            $this->params['doc'] = $value;

        } elseif (is_string($value)) {
            $this->params['doc'] = json_decode($value, true);
        }

        if ($id !== null) {
            $this->currentCommand->id($id)
                ->action('put');

            $this->params['update'] = $update;

        } else {
            $this->currentCommand->action('post');

            $this->params['update'] = false;
        }


        return $this;
    }