dth34653 2014-09-24 12:24
浏览 43
已采纳

Sokil MongoDB从数据库中读取

how can i get the parameters without loop, only read the array $find?

$collection = $tmp->getCollection('X');
$document = [
    'Me' => 'Keyonkeu',
    'Maman' => 'Noubissie',
    'Soeur' => 'Manuella',
    'Papa' => 'SSadi',
    'Age' => 5
];
$collection->createDocument($document)->save();
$find = $collection->find()->where('Age', 5);
var_dump($find);

var_dump return me a lot of classes with private parameters. i cannot read the different parameter (private) directly. Hier is wath var_dump($find) return.

class Sokil\Mongo\QueryBuilder#29 (11) {
  private $_client =>
  class Sokil\Mongo\Client#24 (7) {
    private $_dsn =>
    string(19) "mongodb://127.0.0.1"
    private $_connectOptions =>
    array(1) {
      'connect' =>
      bool(true)
    }
    private $_connection =>
    class MongoClient#25 (4) {
      public $connected =>
      bool(true)
      public $status =>
      NULL
      protected $server =>
      NULL
      protected $persistent =>
      NULL
    }
    private $_databasePool =>
    array(1) {
      'EmoBD' =>
      class Sokil\Mongo\Database#23 (6) {
        ...
      }
    }
    protected $_mapping =>
    array(0) {
    }
    private $_logger =>
    NULL
    private $_currentDatabaseName =>
    string(5) "EmoBD"
  }
  private $_collection =>
  class Sokil\Mongo\Collection#27 (6) {
    protected $_queryBuliderClass =>
    string(25) "\Sokil\Mongo\QueryBuilder"
    protected $_queryExpressionClass =>
    string(23) "\Sokil\Mongo\Expression"
    private $_database =>
    class Sokil\Mongo\Database#23 (6) {
      private $_client =>
      class Sokil\Mongo\Client#24 (7) {
        ...
      }
      private $_databaseName =>
      string(5) "EmoBD"
      private $_mongoDB =>
      class MongoDB#26 (2) {
        ...
      }
      private $_mapping =>
      array(0) {
        ...
      }
      private $_classPrefix =>
      NULL
      private $_collectionPool =>
      array(1) {
        ...
      }
    }
    private $_mongoCollection =>
    class MongoCollection#28 (2) {
      public $w =>
      int(1)
      public $wtimeout =>
      int(10000)
    }
    private $_documentsPool =>
    array(0) {
    }
    protected $_documentPoolEnabled =>
    bool(false)
  }
  private $_fields =>
  array(0) {
  }
  private $_cursor =>
  NULL
  private $_skip =>
  int(0)
  private $_expression =>
  class Sokil\Mongo\Expression#30 (1) {
    protected $_expression =>
    array(1) {
      'Age' =>
      int(5)
    }
  }
  private $_limit =>
  int(0)
  private $_sort =>
  array(0) {
  }
  private $_readPreferences =>
  array(0) {
  }
  protected $_queryExpressionClass =>
  NULL
  private $_options =>
  array(2) {
    'arrayResult' =>
    bool(false)
    'expressionClass' =>
    string(23) "\Sokil\Mongo\Expression"
  }
}

How can read the $find-Array? something like :

$find['...']->get('...')

i don't want to use a loop

  • 写回答

2条回答 默认 最新

  • douzhi4991 2014-10-08 08:16
    关注

    $collection->find()->where('Age', 5) returns cursor, not document or list of documents. So you need to get document or list of documents.

    // get cursor which incapsulates all matched documents
    $cursor = $collection->find()->where('Age', 5);
    // get first from matched documents
    echo $cursor->findOne()->get('Age');
    // get random from matched documents
    echo $cursor->findRandom()->get('Age');
    // get all matched documents as array
    $documentList = $cursor->findAll();
    echo $documentList['some-document-id']->get('Age');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题