added methods to MongoDriver for custom commands, findAndModify, count

This commit is contained in:
Anton Grebnev
2011-11-22 16:29:00 +04:00
parent 54b991314d
commit a87845980d
7 changed files with 156 additions and 7 deletions

View File

@ -26,6 +26,11 @@ class MongoDriver extends NoSqlDbDriver
return $this->connection->selectCollection($this->db, $name);
}
public function count($collection, $query = array(), $limit = 0, $skip = 0)
{
return $this->getCollection($collection)->count($query, $limit, $skip);
}
public function find($collection, $condition = array(), $fields = array())
{
$command = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->getCollection($collection));
@ -48,6 +53,30 @@ class MongoDriver extends NoSqlDbDriver
return $this->query($command, $params);
}
public function findAndModify($collection, $query, $update, $sort = array(), $field = array(), $upsert = false, $new = false, $remove = false)
{
$command = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, $this->getCollection($collection));
$cmd = array(
'findAndModify' => $collection,
'query' => $query,
'update' => $update,
'sort' => $sort,
'fields' => $field,
'new' => $new,
'upsert' => $upsert,
'remove' => $remove
);
$params = array('command' => $cmd);
return $this->query($command, $params);
}
public function command($collection, $cmd)
{
$command = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, $this->getCollection($collection));
$params = array('command' => $cmd);
return $this->query($command, $params);
}
public function insert($collection, $data, $safe = true)
{
$command = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->getCollection($collection));
@ -85,6 +114,8 @@ class MongoDriver extends NoSqlDbDriver
return $this->query($command, $params)->affectedRows();
}
/**
* @param mixed $request
* @return DbStatement