PHPDaemon\Clients\Mongo\Collection::findOne PHP Method

findOne() public method

Finds one object in collection
public findOne ( callable $cb, array $p = [] ) : void
$cb callable Callback called when response received
$p array Hash of properties (offset, opts, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog)
return void
    public function findOne($cb, $p = [])
    {
        $p['col'] = $this->name;
        $this->pool->findOne($p, $cb);
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $ip
  * @param callable $cb
  */
 public function query($ip, $cb)
 {
     if (is_string($ip)) {
         $ip = ip2long($ip);
     }
     $this->blocks->findOne(function ($blk) use($cb) {
         if (!$blk) {
             call_user_func($cb, false);
             return;
         }
         $this->locations->findOne(function ($loc) use($cb) {
             if ($loc) {
                 $loc['country'] = $this->countries[$loc['cc']];
                 $loc['text'] = $loc['country'];
                 if (isset($loc['r']) && !ctype_digit($loc['r'])) {
                     $loc['text'] = $loc['r'] . ', ' . $loc['text'];
                 }
                 if (isset($loc['c'])) {
                     $loc['text'] = $loc['c'] . ', ' . $loc['text'];
                 }
             }
             call_user_func($cb, $loc);
         }, ['where' => ['_id' => $blk['l']]]);
     }, ['where' => ['s' => ['$lte' => $ip]], 'sort' => ['s' => -1]]);
 }
All Usage Examples Of PHPDaemon\Clients\Mongo\Collection::findOne