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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭