本文整理汇总了PHP中MongoCollection::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::findOne方法的具体用法?PHP MongoCollection::findOne怎么用?PHP MongoCollection::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findOne
public function findOne($email)
{
$one = $this->contactsManagerCollection->findOne(array('email' => $email));
if ($one != null) {
return $this->createContact($one);
}
}
示例2: get
/**
* Get data by key if not expired
* @param $key
* @return string
*/
protected function get($key)
{
$record = $this->mongoCollection->findOne(array('key' => $key));
if ($record && is_array($record) && array_key_exists('data', $record)) {
return $record['data'];
}
}
示例3: getLogById
/**
* Retrieve a log entry by his ID.
*
* @param string $id
*
* @return Log|null
*/
public function getLogById($id)
{
$log = $this->collection->findOne(array('_id' => array('$eq' => new \MongoId($id))));
if (!$log) {
return null;
}
return $this->convertArrayToEntity($log);
}
示例4: findByEmail
/**
* {@inheritdoc}
*/
public function findByEmail(EmailAddress $email)
{
$persistedState = $this->collection->findOne(['email' => (string) $email]);
if ($persistedState === null) {
return null;
}
return AccountCredentials::fromPersistedState($persistedState);
}
示例5: read
/**
* Read Session Data
*
* @param string $id
* Session Data ID
*
* @return string|NULL
*
* If the fetching process was successfully completed and read data
* is not corrupted, a string will be returned.
*
* Otherwise, NULL will
*/
public function read($id)
{
$data = $this->collection->findOne(array('_id' => $id), array('serialized'));
if (isset($data['serialized']) && $data['serialized'] instanceof \MongoBinData) {
return gzuncompress($data['serialized']->bin);
}
return NULL;
}
示例6: exists
/**
*/
public function exists($tokenID)
{
try {
return !is_null($this->_db->findOne(array(self::ADDRESS => $this->_encodeRemoteAddress(), self::TID => $tokenID)));
} catch (MongoException $e) {
return false;
}
}
示例7: get
/**
* Retrieve the cached results of the api $request.
*
* @param RequestInterface $request A request for which the response may be cached.
*
* @return ResponseInterface|null
*/
public function get(RequestInterface $request)
{
$cached = $this->collection->findOne(['_id' => $request->getUrl()]);
if ($cached === null) {
return null;
}
return new Response($cached['httpCode'], $cached['headers'], $cached['body']);
}
示例8: get
/**
* Retrieves the cache item for the given id.
*
* @param string $key The cache key to retrieve.
* @return mixed|null Returns the cached data or null.
*/
public function get($key)
{
$cache = $this->collection->findOne(array('key' => $key), array('data', 'expire'));
if ($cache !== null) {
$this->ttls[$key] = isset($cache['expire']) ? $cache['expire']->sec - time() : 0;
}
return $cache;
}
示例9: getLockInfo
/**
*/
public function getLockInfo($lockid)
{
$query = array(self::LID => $lockid, '$or' => array(array(self::EXPIRY_TS => array('$gte' => time())), array(self::EXPIRY_TS => Horde_Lock::PERMANENT)));
try {
return $this->_mapFields($this->_db->findOne($query));
} catch (MongoException $e) {
throw new Horde_Lock_Exception($e);
}
}
示例10: getGroup
protected function getGroup($identifier)
{
$res = $this->collection->findOne([self::FIELD_TYPE => self::RECORD_TYPE_KEYWORD, self::FIELD_IDENTIFIER => $identifier]);
if ($res) {
return $res[self::FIELD_GROUP];
} else {
throw new \RuntimeException('Could not get group name. Identifier is not subscribed');
}
}
示例11: findOne
public function findOne($criteria)
{
$result = null;
$document = $this->mongoCollection->findOne($criteria);
if ($document) {
$result = $this->objectFactory->unmarshal($document);
}
return $result;
}
示例12: search
public function search($query)
{
$results = [];
$data = $this->index->findOne(array('token' => $query));
if (!isset($data)) {
return $results;
}
return $data['documents'];
}
示例13: insertOrUpdate
public function insertOrUpdate($product)
{
$result = $this->collection->findOne(['product_id' => $product['product_id']]);
if ($result) {
$this->update($product);
} else {
$this->insert($product);
}
}
示例14: isCached
/**
* {@inheritDoc}
*/
public function isCached($providerName, $query)
{
$result = $this->collection->findOne(array('id' => $this->getKey($providerName, $query)));
if (null === $result) {
return false;
}
$cached = new BatchGeocoded();
$cached->fromArray($result);
return $cached;
}
示例15: get
/**
* {@inheritdoc }
*/
public function get($key)
{
$tKey = $this->getKey($key);
$tNow = $this->getTtl();
$data = $this->collection->findOne(array('_id' => $tKey, 'ttl' => array('$gte' => $tNow)));
if (isset($data)) {
return $this->unPack($data['value']);
}
return false;
}