Skip to content

Instantly share code, notes, and snippets.

@tommoor
Created September 4, 2011 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommoor/1193229 to your computer and use it in GitHub Desktop.
Save tommoor/1193229 to your computer and use it in GitHub Desktop.
Temporary profiling solution for Codeigniter Mongo_db library
<?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