added butchInsert to mongo model
This commit is contained in:
@ -121,10 +121,16 @@ class InsertMongoCommand extends MongoDbCommand
|
||||
|
||||
protected $insertId = false;
|
||||
|
||||
protected $multiple = false;
|
||||
|
||||
protected function concreteExecute()
|
||||
{
|
||||
$result = $this->collection->insert($this->data, array('safe' => $this->safe));
|
||||
$this->insertId = $this->data['_id'];
|
||||
if (!$this->multiple) {
|
||||
$result = $this->collection->insert($this->data, array('safe' => $this->safe));
|
||||
$this->insertId = $this->data['_id'];
|
||||
} else {
|
||||
$result = $this->collection->batchInsert($this->data, array('safe' => $this->safe));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -150,6 +156,8 @@ class InsertMongoCommand extends MongoDbCommand
|
||||
var_dump($this->data);
|
||||
$data = ob_get_clean();
|
||||
$result .= 'Data: ' . $data . PHP_EOL;
|
||||
$mult = $this->multiple ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Bulk insert: ' . $mult . PHP_EOL;
|
||||
$safe = $this->safe ? 'TRUE' : 'FALSE';
|
||||
$result .= 'Safe operation: ' . $safe . PHP_EOL;
|
||||
return $result;
|
||||
@ -174,13 +182,13 @@ class UpdateMongoCommand extends MongoDbCommand
|
||||
protected function concreteExecute()
|
||||
{
|
||||
return $this->collection->update($this->condition, $this->data,
|
||||
array('multiple' => $this->multiple, 'upsert' => $this->upsert, 'safe' => $this->safe));
|
||||
array('multiple' => $this->multiple, 'upsert' => $this->upsert, 'safe' => $this->safe));
|
||||
}
|
||||
|
||||
protected function checkParams()
|
||||
{
|
||||
if (isset($this->collection) && isset($this->condition) && isset($this->data) &&
|
||||
isset($this->upsert) && isset($this->safe)
|
||||
isset($this->upsert) && isset($this->safe)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -77,12 +77,13 @@ class MongoDriver extends NoSqlDbDriver
|
||||
return $this->query($command, $params);
|
||||
}
|
||||
|
||||
public function insert($collection, $data, $safe = true)
|
||||
public function insert($collection, $data, $multiple = false, $safe = true)
|
||||
{
|
||||
$command = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->getCollection($collection));
|
||||
$params = array(
|
||||
'data' => $data,
|
||||
'safe' => $safe
|
||||
'safe' => $safe,
|
||||
'multiple' => $multiple
|
||||
);
|
||||
$result = $this->query($command, $params);
|
||||
$this->last_insert_id = $result->getInsertId();
|
||||
|
@ -32,18 +32,23 @@ abstract class MongoModel extends Model
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
if($this->useMongoId) {
|
||||
if(! $id instanceof MongoId) {
|
||||
if ($this->useMongoId) {
|
||||
if (!$id instanceof MongoId) {
|
||||
$id = new MongoId($id);
|
||||
}
|
||||
}
|
||||
return $this->db->get($this->table(), array('_id' => $id))->fetch();
|
||||
}
|
||||
|
||||
public function batchInsert($data)
|
||||
{
|
||||
return $this->db->insert($this->table(), $data, true);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
if($this->useMongoId) {
|
||||
if(! $id instanceof MongoId) {
|
||||
if ($this->useMongoId) {
|
||||
if (!$id instanceof MongoId) {
|
||||
$id = new MongoId($id);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user