From 08cfc212102d15d8214402e01e4be8dd6f7cdaf0 Mon Sep 17 00:00:00 2001 From: Kevin Lai Date: Wed, 27 Sep 2017 15:53:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmongo=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Fasim/Db/Mongodb.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Fasim/Db/Mongodb.php b/src/Fasim/Db/Mongodb.php index e8e0277..5790143 100644 --- a/src/Fasim/Db/Mongodb.php +++ b/src/Fasim/Db/Mongodb.php @@ -14,8 +14,8 @@ class Mongodb implements IDB { protected $_config = array(); protected $_uri = ''; protected $_options = []; - protected $manager = null; - protected $database = ''; + protected $_manager = null; + protected $_database = ''; function __construct($config, $uri){ $this->_config = $config; @@ -40,8 +40,8 @@ public function connect() { // $options['replicaSet'] = $this->_config['replicaSet']; // } - $this->manager = new \MongoDB\Driver\Manager($this->_uri, $this->_options); - $this->database = $this->_config['database']; + $this->_manager = new \MongoDB\Driver\Manager($this->_uri, $this->_options); + $this->_database = $this->_config['database']; } @@ -51,7 +51,7 @@ public function setDebug($debug) { public function find($data) { - if (!$this->_mongo) { + if (!$this->_manager) { $this->connect(); } $filter = $data['where']; @@ -88,34 +88,34 @@ public function find($data) { $options['skip'] = $data['offset']; } $query = new \MongoDB\Driver\Query($filter, $options); - $cursor = $this->manager->executeQuery($this->database . '.' . $data['table'], $query); + $cursor = $this->_manager->executeQuery($this->_database . '.' . $data['table'], $query); $result = $cursor->toArray(); return $result; } public function count($table, $query) { - if (!$this->_mongo) { + if (!$this->_manager) { $this->connect(); } $cmd = new \MongoDB\Driver\Command([ 'count' => $table, 'query' => $query ]); - $cursor = $this->manager->executeCommand($this->database, $cmd); + $cursor = $this->_manager->executeCommand($this->_database, $cmd); $response = $cursor->toArray(); return count($response) > 0 ? intval($response[0]->n) : 0; } public function insert($table, $data, $returnId) { - if (!$this->_mongo) { + if (!$this->_manager) { $this->connect(); } $bulk = new \MongoDB\Driver\BulkWrite(['ordered' => true]); $bulk->insert($data); $writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000); - return $this->manager->executeBulkWrite($this->database . '.' . $table, $bulk, $writeConcern); + return $this->_manager->executeBulkWrite($this->_database . '.' . $table, $bulk, $writeConcern); //print_r($data); } public function update($table, $where, $data) { - if (!$this->_mongo) { + if (!$this->_manager) { $this->connect(); } $bulk = new \MongoDB\Driver\BulkWrite(['ordered' => true]); @@ -123,19 +123,19 @@ public function update($table, $where, $data) { $updates = ['$set' => $data]; $bulk->update($where, $updates, $options); $writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000); - return $this->manager->executeBulkWrite($this->database . '.' . $table, $bulk, $writeConcern); + return $this->_manager->executeBulkWrite($this->_database . '.' . $table, $bulk, $writeConcern); //print_r($result); } public function delete($table, $where) { - if (!$this->_mongo) { + if (!$this->_manager) { $this->connect(); } $bulk = new \MongoDB\Driver\BulkWrite(['ordered' => true]); $options = array('multi' => true, 'upsert' => false); $bulk->delete($where, $options); $writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000); - return $this->manager->executeBulkWrite($this->database . '.' . $table, $bulk, $writeConcern); + return $this->_manager->executeBulkWrite($this->_database . '.' . $table, $bulk, $writeConcern); //print_r($result); }