Last active
August 29, 2015 14:24
-
-
Save sokil/98131d420f4c2da22ffd to your computer and use it in GitHub Desktop.
MongoInsertBatch
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 | |
/** | |
* @link https://github.com/mongodb/mongo-php-driver/blob/v1.6/bson.c#L89 | |
*/ | |
// connection | |
$client = new MongoClient("mongodb://localhost"); | |
$collection = $client->test->test; | |
// batch operation | |
$batch = new MongoInsertBatch($collection); | |
// value | |
class Value | |
{ | |
protected $value = []; | |
public function toArray() { return $this->value; } | |
public function __set($name, $value) { $this->value[$name] = $value; } | |
} | |
$value = new Value(); | |
$value->param = 42; | |
// add batch | |
$batch->add($value->toArray()); | |
var_dump($value->toArray()); | |
/* | |
array(2) { | |
'param' => | |
int(42) | |
'_id' => | |
class MongoId#6 (1) { | |
public $$id => | |
string(24) "55937c2f2de5729e158b4567" | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment