public function one()
    {
        try {
            $mongoDocument = $this->collection
                ->getMongoCollection()
                ->findOne(
                    $this->expression->toArray(),
                    $this->projection
                );
        } catch (\Exception $e) {
            throw new CursorException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        if (empty($mongoDocument)) {
            return null;
        }

        if (true === $this->isResultAsArray) {
            return $mongoDocument;
        }

        return $this->collection->hydrate(
            $mongoDocument,
            $this->isDocumentPoolUsed()
        );
    }
public function one()
    {
        try {
            $mongoDocument = $this->collection
                ->getMongoCollection()
                ->findOne(
                    $this->expression->toArray(),
                    $this->projection
                );
        } catch (\Exception $e) {
            throw new CursorException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        if (empty($mongoDocument)) {
            return null;
        }

        if (true === $this->isResultAsArray) {
            return $mongoDocument;
        }

        return $this->collection->hydrate(
            $mongoDocument,
            $this->isDocumentPoolUsed()
        );
    }
public function one ( ) { try { $ mongoDocument = $ this -> collection -> getMongoCollection ( ) -> findOne ( $ this -> expression -> toArray ( ) , $ this -> projection ) ; } catch ( \ Exception $ e ) { throw new CursorException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } if ( empty ( $ mongoDocument ) ) { return null ; } if ( true === $ this -> isResultAsArray ) { return $ mongoDocument ; } return $ this -> collection -> hydrate ( $ mongoDocument , $ this -> isDocumentPoolUsed ( ) ) ; }
Find one document which correspond to expression.

If multiple documents satisfy the query, this method returns the first document according to the natural order
which reflects the order of documents on the disk.
In capped collections, natural order is the same as insertion order.
If no document satisfies the query, the method returns null.

@see https://docs.mongodb.com/manual/reference/method/db.collection.findOne/

@return Document|array|null

@throws CursorException
@throws Exception
Find one document which correspond to expression .