/**
  * @dataProvider provideTypeMapOptionsAndExpectedDocument
  */
 public function testTypeMapOption(array $typeMap, $expectedDocument)
 {
     $this->createFixtures(1);
     $operation = new FindOne($this->getDatabaseName(), $this->getCollectionName(), [], ['typeMap' => $typeMap]);
     $document = $operation->execute($this->getPrimaryServer());
     $this->assertEquals($expectedDocument, $document);
 }
Esempio n. 2
0
 /**
  * Finds a single document matching the query.
  *
  * @see FindOne::__construct() for supported options
  * @see http://docs.mongodb.org/manual/core/read-operations-introduction/
  * @param array|object $filter  Query by which to filter documents
  * @param array        $options Additional options
  * @return object|null
  */
 public function findOne($filter = [], array $options = [])
 {
     if (!isset($options['readConcern'])) {
         $options['readConcern'] = $this->readConcern;
     }
     if (!isset($options['readPreference'])) {
         $options['readPreference'] = $this->readPreference;
     }
     if (!isset($options['typeMap'])) {
         $options['typeMap'] = $this->typeMap;
     }
     $operation = new FindOne($this->databaseName, $this->collectionName, $filter, $options);
     $server = $this->manager->selectServer($options['readPreference']);
     return $operation->execute($server);
 }
 /**
  * Finds a single document matching the query.
  *
  * @see FindOne::__construct() for supported options
  * @see http://docs.mongodb.org/manual/core/read-operations-introduction/
  * @param array|object $filter  Query by which to filter documents
  * @param array        $options Additional options
  * @return object|null
  */
 public function findOne($filter = array(), array $options = array())
 {
     $operation = new FindOne($this->databaseName, $this->collectionName, $filter, $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }