find() public method

Create document query builder
public find ( $callable = null ) : Cursor | Expression
$callable callable|null Function to configure query builder&
return Cursor | Expression
Ejemplo n.º 1
0
 public function testFlush()
 {
     $document = $this->collection->createDocument(array('param' => 'value'));
     // add document
     $this->persistence->persist($document)->flush();
     $this->assertEquals('value', $this->collection->find()->findOne()->param);
 }
Ejemplo n.º 2
0
 /**
  * Get item from queue as is
  * 
  * @return mixed
  */
 public function dequeuePlain()
 {
     $document = $this->collection->find()->sort(array('priority' => -1, 'datetime' => 1))->findAndRemove();
     if (!$document) {
         return null;
     }
     return $document->get('payload');
 }
Ejemplo n.º 3
0
 public function testHashEquals()
 {
     $queryBuilder1 = $this->collection->find()->field('_id')->field('ineterests')->sort(array('age' => 1, 'gender' => -1))->limit(10, 20)->whereAll('interests', array('php', 'snowboard'));
     $queryBuilder2 = $this->collection->find()->sort(array('gender' => -1, 'age' => 1))->field('ineterests')->whereAll('interests', array('php', 'snowboard'))->field('_id')->limit(10, 20);
     $queryBuilder3 = $this->collection->find()->sort(array('age' => 1))->whereAll('interests', array('php', 'snowboard'))->field('_id')->limit(10, 20);
     $this->assertEquals($queryBuilder1->getHash(), $queryBuilder2->getHash());
     $this->assertNotEquals($queryBuilder1->getHash(), $queryBuilder3->getHash());
 }
Ejemplo n.º 4
0
 public function testExpressionWithinPolygon()
 {
     $this->collection->ensure2dIndex('point');
     $point1Id = $this->collection->createDocument()->setLegacyPoint('point', 5, 4)->save()->getId();
     $point2Id = $this->collection->createDocument()->setLegacyPoint('point', 50, 40)->save()->getId();
     $point = $this->collection->find()->withinPolygon('point', array(array(0, 0), array(0, 10), array(10, 10), array(10, 0)))->findOne();
     $this->assertNotEmpty($point);
     $this->assertEquals($point1Id, $point->getId());
 }
 /**
  * @dataProvider persistanceInstanceProvider
  */
 public function testPersistUpdate(Persistence $persistence)
 {
     // store document
     $documentId = $this->collection->createDocument(array('param' => 'value'))->save()->getId();
     // get document directly and change
     $document = $this->collection->getDocumentDirectly($documentId);
     $document->param = 'new';
     // add document
     $persistence->persist($document)->flush();
     // get document directly and check
     $this->assertEquals('new', $this->collection->find()->findOne()->param);
 }
Ejemplo n.º 6
0
 public function testGetResultSet()
 {
     $document1Id = $this->collection->createDocument(array('param' => 1))->save()->getId();
     $document2Id = $this->collection->createDocument(array('param' => 2))->save()->getId();
     $document3Id = $this->collection->createDocument(array('param' => 3))->save()->getId();
     $document4Id = $this->collection->createDocument(array('param' => 4))->save()->getId();
     $resultSet = $this->collection->find()->getResultSet();
     $this->assertInstanceOf('\\Sokil\\Mongo\\ResultSet', $resultSet);
     $filtered = $resultSet->filter(function ($item) {
         return $item->param % 2;
     })->keys();
     $this->assertEquals(array($document1Id, $document3Id), $filtered);
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider persistanceInstanceProvider
  */
 public function testRemove(Persistence $persistence)
 {
     $document = $this->collection->createDocument(array('param' => 'value'))->save();
     // add document
     $persistence->remove($document);
     // check if document in persistence
     $this->assertTrue($persistence->contains($document));
     // store to disk
     $persistence->flush();
     // check if document in persistence
     $this->assertFalse($persistence->contains($document));
     // check if document removed
     $this->assertEmpty($this->collection->find()->findOne());
 }
Ejemplo n.º 8
0
 public function testPaginatorIteratorInterface()
 {
     $d11 = $this->collection->createDocument(array('param1' => 1, 'param2' => 1))->save();
     $d12 = $this->collection->createDocument(array('param1' => 1, 'param2' => 2))->save();
     $d21 = $this->collection->createDocument(array('param1' => 2, 'param2' => 1))->save();
     $d22 = $this->collection->createDocument(array('param1' => 2, 'param2' => 2))->save();
     $pager = $this->collection->find()->paginate(20, 2);
     $this->assertEquals($d21->getId(), $pager->current()->getId());
     $this->assertEquals((string) $d21->getId(), $pager->key());
     $this->assertTrue($pager->valid());
     $pager->next();
     $this->assertEquals($d22->getId(), $pager->current()->getId());
     $this->assertEquals((string) $d22->getId(), $pager->key());
     $this->assertTrue($pager->valid());
     $pager->next();
     $this->assertFalse($pager->valid());
     $pager->rewind();
     $this->assertEquals($d21->getId(), $pager->current()->getId());
     $this->assertEquals((string) $d21->getId(), $pager->key());
 }