Skip to content

Instantly share code, notes, and snippets.

@tholder
Created December 23, 2011 21:38
Show Gist options
  • Save tholder/1515424 to your computer and use it in GitHub Desktop.
Save tholder/1515424 to your computer and use it in GitHub Desktop.
Puling an array item matching a value
<?php
public function testPullTest()
{
$doc = new Model_Mongo_Lab();
$doc->laboratory = new Shanty_Mongo_Document();
$doc->laboratory->mixtures = array(
array(
'id' => 'abc',
'name' => 'string 1'
),
array(
'id' => '123',
'name' => 'string 2'
),
);
$doc->save();
$loadedDoc = Model_Mongo_Lab::find($doc->getId());
$this->assertEquals('string 1', $loadedDoc->laboratory->mixtures[0]->name);
$doc->addOperation('$pull', 'laboratory.mixtures', array('id'=> 'abc'));
$doc->save();
$loadedDoc = Model_Mongo_Lab::find($doc->getId());
$this->assertEquals('string 2', $loadedDoc->laboratory->mixtures[0]->name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment