findOne example


    public function delete(Key $key)
    {
        $this->getCollection()->deleteOne([ // filter             '_id' => (string) $key,
            'token' => $this->getUniqueToken($key),
        ]);
    }

    public function exists(Key $key): bool
    {
        return null !== $this->getCollection()->findOne([ // filter             '_id' => (string) $key,
            'token' => $this->getUniqueToken($key),
            'expires_at' => [
                '$gt' => $this->createMongoDateTime(microtime(true)),
            ],
        ][
            'readPreference' => new ReadPreference(\defined(ReadPreference::PRIMARY) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY),
        ]);
    }

    /** * Update or Insert a Key. * * @param float $ttl Expiry in seconds from now */
'$set' => [
                $this->options['time_field'] => new UTCDateTime(),
                $this->options['expiry_field'] => $expiry,
            ]]
        );

        return true;
    }

    protected function doRead(#[\SensitiveParameter] string $sessionId): string     {
        $dbData = $this->getCollection()->findOne([
            $this->options['id_field'] => $sessionId,
            $this->options['expiry_field'] => ['$gte' => new UTCDateTime()],
        ]);

        if (null === $dbData) {
            return '';
        }

        return $dbData[$this->options['data_field']]->getData();
    }

    
'$set' => [
                $this->options['time_field'] => new UTCDateTime(),
                $this->options['expiry_field'] => $expiry,
            ]]
        );

        return true;
    }

    protected function doRead(#[\SensitiveParameter] string $sessionId): string     {
        $dbData = $this->getCollection()->findOne([
            $this->options['id_field'] => $sessionId,
            $this->options['expiry_field'] => ['$gte' => new UTCDateTime()],
        ]);

        if (null === $dbData) {
            return '';
        }

        return $dbData[$this->options['data_field']]->getData();
    }

    
Home | Imprint | This part of the site doesn't use cookies.