This file contains hidden or 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 | |
$m = new MongoClient(); | |
$c = $m->test->foo; | |
$c->drop(); | |
$c->insert(['_id' => 1, 'x' => str_repeat('z', 1024*1024*4)]); | |
$c->insert(['_id' => 2, 'x' => str_repeat('z', 1024*1024*4)]); | |
$c->insert(['_id' => 3, 'x' => str_repeat('z', 1024*1024*4)]); | |
$c->insert(['_id' => 4, 'x' => str_repeat('z', 1024*1024*4)]); | |
$c->insert(['_id' => 5, 'x' => str_repeat('z', 1024*1024*4)]); |
This file contains hidden or 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 | |
class BadIdeaIterator implements Iterator | |
{ | |
protected $position; | |
protected $keys; | |
protected $values; | |
public function __construct(array $keys, array $values) | |
{ |
This file contains hidden or 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 | |
$mongoClient = new MongoClient('mongodb://localhost'); | |
$collection = $mongoClient->selectCollection('mydb', 'customers'); | |
// Assume $parms exists as an associative array (perhaps from $_POST) | |
$rp = 'listcustomer'; | |
switch ($rp) { | |
case 'listcustomers': |
This file contains hidden or 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 | |
/** | |
* Testing replica set step down and node removal | |
* | |
* Assumes a three-member replica set is running: | |
* | |
* mongod --port 2000 --dbpath /data/rs0-db0 --replSet rs0 | |
* mongod --port 2001 --dbpath /data/rs0-db1 --replSet rs0 | |
* mongod --port 2002 --dbpath /data/rs0-db2 --replSet rs0 |
This file contains hidden or 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
#!/usr/bin/env php | |
<?php | |
require_once 'config.php'; // mongodb-odm/tools/sandbox/config.php | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | |
/** | |
* Test batch insertion of documents and referenced GridFS files. | |
* |
This file contains hidden or 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 | |
namespace Acme\FooBundle\Command; | |
use Doctrine\Common\Persistence\ManagerRegistry; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class FindInvalidReferencesCommand extends ContainerAwareCommand |
This file contains hidden or 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
/** | |
* Initialize the database collection for querying. | |
*/ | |
var init = function() { | |
db.foo.drop(); | |
for (var i = 0; i < 10; ++i) { | |
for (var j = i; j < 100000; j += 10) { | |
db.foo.insert({x: j, y: j}); | |
} | |
} |
This file contains hidden or 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
> db.foo.find({ name: { $all : [/^c/, /^d/] } }); | |
{ "_id" : ObjectId("5000358de84df15c27000000"), "name" : [ "john", "martin", "chuck", "dave" ] } | |
{ "_id" : ObjectId("5000358de84df15c27000001"), "name" : [ "craig", "don", "dan" ] } |
This file contains hidden or 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 | |
// dump.php [database] [collection] [filename] | |
function dump(MongoCollection $collection, $filename) { | |
$file = fopen($filename, 'w'); | |
foreach ($collection->find() as $document) { | |
fwrite($file, bson_encode($document)); | |
} |
This file contains hidden or 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 | |
$m = new Mongo(); | |
$c = $m->test->foo; | |
$c->drop(); | |
$a = microtime(true); | |
foreach (range(1,1000000) as $i) { | |
$c->insert(array('x' => $i)); | |
} |