public function firstExample($collectionId, $document, array $options = [])
    {
        $_documentClass = $this->_documentClass;

        if (is_array($document)) {
            $document = $_documentClass::createFromArray($document, $options);
        }

        if (!($document instanceof Document)) {
            throw new ClientException('Invalid example document specification');
        }

        $data = [
            self::OPTION_COLLECTION => $collectionId,
            self::OPTION_EXAMPLE    => $document->getAll(['_ignoreHiddenAttributes' => true])
        ];

        $response = $this->getConnection()->put(Urls::URL_FIRST_EXAMPLE, $this->json_encode_wrapper($data));
        
        if ($batchPart = $response->getBatchPart()) {
            return $batchPart;
        }
        
        $data     = $response->getJson();

        $options['_isNew'] = false;

        return $_documentClass::createFromArray($data['document'], $options);
    }
public function firstExample($collectionId, $document, array $options = [])
    {
        $_documentClass = $this->_documentClass;

        if (is_array($document)) {
            $document = $_documentClass::createFromArray($document, $options);
        }

        if (!($document instanceof Document)) {
            throw new ClientException('Invalid example document specification');
        }

        $data = [
            self::OPTION_COLLECTION => $collectionId,
            self::OPTION_EXAMPLE    => $document->getAll(['_ignoreHiddenAttributes' => true])
        ];

        $response = $this->getConnection()->put(Urls::URL_FIRST_EXAMPLE, $this->json_encode_wrapper($data));
        
        if ($batchPart = $response->getBatchPart()) {
            return $batchPart;
        }
        
        $data     = $response->getJson();

        $options['_isNew'] = false;

        return $_documentClass::createFromArray($data['document'], $options);
    }
public function firstExample ( $ collectionId , $ document , array $ options = [ ] ) { $ _documentClass = $ this -> _documentClass ; if ( is_array ( $ document ) ) { $ document = $ _documentClass :: createFromArray ( $ document , $ options ) ; } if ( ! ( $ document instanceof Document ) ) { throw new ClientException ( 'Invalid example document specification' ) ; } $ data = [ self :: OPTION_COLLECTION => $ collectionId , self :: OPTION_EXAMPLE => $ document -> getAll ( [ '_ignoreHiddenAttributes' => true ] ) ] ; $ response = $ this -> getConnection ( ) -> put ( Urls :: URL_FIRST_EXAMPLE , $ this -> json_encode_wrapper ( $ data ) ) ; if ( $ batchPart = $ response -> getBatchPart ( ) ) { return $ batchPart ; } $ data = $ response -> getJson ( ) ; $ options [ '_isNew' ] = false ; return $ _documentClass :: createFromArray ( $ data [ 'document' ] , $ options ) ; }
Get the first document matching a given example.

This will throw if the document cannot be fetched from the server


@throws Exception

@param mixed $collectionId      - collection id as string or number
@param mixed $document          - the example document as a Document object or an array
@param array $options           - optional, an array of options.
<p>Options are :<br>
<li>'_sanitize'         - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document. <br>
The difference is, that if you're returning a result set of documents, the getAll() is already called <br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
</li>
</p>

@return Document - the document fetched from the server
@since 1.2
Get the first document matching a given example .