Created
September 4, 2011 18:00
-
-
Save tommoor/1193229 to your computer and use it in GitHub Desktop.
Temporary profiling solution for Codeigniter Mongo_db library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function get($collection = "") | |
{ | |
if (empty($collection)) | |
{ | |
show_error("In order to retreive documents from MongoDB, a collection name must be passed", 500); | |
} | |
if (isset($this->wheres['_id']) and ! ($this->wheres['_id'] instanceof MongoId)) | |
{ | |
$this->wheres['_id'] = new MongoId($this->wheres['_id']); | |
} | |
// benchmarking | |
$query = $collection . ' : ' . str_replace('"', ' ', json_encode($this->wheres)); | |
$this->CI->benchmark->mark($query . '_start'); | |
$documents = $this->db->{$collection}->find($this->wheres, $this->selects)->limit((int) $this->limit)->skip((int) $this->offset)->sort($this->sorts); | |
// Clear | |
$this->_clear(); | |
$returns = array(); | |
while ($documents->hasNext()) | |
{ | |
$returns[] = (object) $documents->getNext(); | |
} | |
// benchmarking | |
$this->CI->benchmark->mark($query . '_end'); | |
if ($this->CI->config->item('mongo_return') == 'object') | |
{ | |
return (object)$returns; | |
} | |
else | |
{ | |
return $returns; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment