private function doQuery(Description $queryDescription, QueryOptions $queryOptions = null, $entityType) { $cursor = $this->database->selectCollection($entityType)->find($this->buildQueryForDescription($queryDescription, new Expr())->getQuery(), $this->buildQueryModifiers()); if ($queryOptions === null) { return $cursor; } return $this->applyOptionsToCursor($cursor, $queryOptions); }
/** * @see EntityDocumentLookup::getEntityDocumentsForTerm */ public function getEntityIdsForTerm(Term $term, $entityType) { $documents = $this->database->selectCollection($entityType)->find($this->buildGetEntityIdForTermQuery($term), array('_id' => 1)); $entities = array(); foreach ($documents as $document) { $entities[] = $this->documentBuilder->buildEntityIdForDocument($document); } return $entities; }
/** * Execute the mapReduce command. * * @see Collection::mapReduce() * @param string|\MongoCode $map * @param string|\MongoCode $reduce * @param array|string $out * @param array $query * @param array $options * @return ArrayIterator * @throws ResultException if the command fails */ protected function doMapReduce($map, $reduce, $out, array $query, array $options) { $options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options; $command = array(); $command['mapreduce'] = $this->mongoCollection->getName(); $command['map'] = $map; $command['reduce'] = $reduce; $command['query'] = (object) $query; $command['out'] = $out; $command = array_merge($command, $options); foreach (array('map', 'reduce', 'finalize') as $key) { if (isset($command[$key]) && is_string($command[$key])) { $command[$key] = new \MongoCode($command[$key]); } } $result = $this->database->command($command); if (empty($result['ok'])) { throw new ResultException($result); } if (isset($result['result']) && is_string($result['result'])) { return $this->database->selectCollection($result['result'])->find(); } if (isset($result['result']) && is_array($result['result']) && isset($result['result']['db'], $result['result']['collection'])) { return $this->database->getConnection()->selectCollection($result['result']['db'], $result['result']['collection'])->find(); } $arrayIterator = new ArrayIterator(isset($result['results']) ? $result['results'] : array()); $arrayIterator->setCommandResult($result); return $arrayIterator; }
private function setupClaimsIndexes() { foreach (MongoDBDocumentBuilder::$SUPPORTED_ENTITY_TYPES as $entityType) { $collection = $this->database->selectCollection($entityType); foreach (MongoDBDocumentBuilder::$SUPPORTED_DATAVALUE_TYPES as $dataValueType) { $key = 'sclaims.' . $dataValueType; $collection->ensureIndex([$key => 1], ['sparse' => true, 'socketTimeoutMS' => -1]); } } }
public function testDeleteAclRemovesOidAndAces() { $provider = $this->getProvider(); $oid = new ObjectIdentity(1, 'Foo'); $acl = $provider->createAcl($oid); $acl->insertObjectAce(new RoleSecurityIdentity('ROLE_USER'), 1); $provider->updateAcl($acl); $provider->deleteAcl($oid); $options = $this->getOptions(); $oidCursor = $this->con->selectCollection($options['oid_collection'])->find(); $entryCursor = $this->con->selectCollection($options['entry_collection'])->find(); $this->assertEquals(0, $oidCursor->count()); $this->assertEquals(0, $entryCursor->count()); }
public function up(Database $db) { $dm = $this->container->get('doctrine_mongodb')->getManager(); $deleted = $db->selectCollection('Node')->createQueryBuilder()->field('deleted')->equals(true)->getQuery()->execute(); $facetRepo = $dm->getRepository('BpiApiBundle:Entity\\Facet'); foreach ($deleted as $node) { if (isset($node['_id'])) { $facet = $facetRepo->findOneByNodeId((string) $node['_id']); if ($facet) { $dm->remove($facet); $dm->flush(); } } } }
public function up(Database $db) { $collection = $db->selectCollection('Template'); $templates = $collection->find([], ['files' => 1, 'id' => 1]); foreach ($templates as $template) { foreach ($template['files'] as $ii => $file) { $isImage = preg_match('/\\.(jpg|png|gif)$/', $file['clientPath']) === 1; if (!$isImage) { continue; } if (isset($file['attributes']['width']) && isset($file['attributes']['height'])) { continue; } list($width, $height) = getimagesize($file['fileSystemUrl']); $collection->update(['id' => $template['id'], 'files.clientPath' => $file['clientPath']], ['$set' => ['files.' . $ii . '.attributes.width' => $width, 'files.' . $ii . '.attributes.height' => $height]]); } } }
protected function doMapReduce($map, $reduce, array $query, array $options) { if (is_string($map)) { $map = new \MongoCode($map); } if (is_string($reduce)) { $reduce = new \MongoCode($reduce); } $command = array(); $command['mapreduce'] = $this->mongoCollection->getName(); $command['map'] = $map; $command['reduce'] = $reduce; $command['query'] = $query; $command = array_merge($command, $options); $result = $this->database->command($command); if (!$result['ok']) { throw new \RuntimeException($result['errmsg']); } return $this->database->selectCollection($result['result'])->find(); }
public function down(Database $db) { $collection = $db->selectCollection('Company'); $companies = $collection->find(); foreach ($companies as $company) { if (!isset($company['address']) || count($company['address']) === 0) { continue; } $downNeeded = false; foreach ($this->arrayIndexesThatIndicateMigrated as $index) { if (isset($company['address'][$index])) { $downNeeded = true; break; } } if (!$downNeeded) { continue; } // Convert back to array of objects. $collection->update(['_id' => $company['_id']], ['$set' => ['address' => [$company['address']]]]); } }
protected function doMapReduce($map, $reduce, array $out, array $query, array $options) { if (is_string($map)) { $map = new \MongoCode($map); } if (is_string($reduce)) { $reduce = new \MongoCode($reduce); } $command = array(); $command['mapreduce'] = $this->getMongoCollection()->getName(); $command['map'] = $map; $command['reduce'] = $reduce; $command['query'] = (object) $query; $command['out'] = $out; $command = array_merge($command, $options); $result = $this->database->command($command); if (!$result['ok']) { throw new \RuntimeException($result['errmsg']); } if (isset($out['inline']) && $out['inline'] === true) { return new ArrayIterator($result['results']); } return $this->database->selectCollection($result['result'])->find(); }
/** * Get the collection which records whether a migration has been applied. * * @return \Doctrine\MongoDB\Collection */ public function getAppliedCollection() { return $this->database->selectCollection('MongrateMigrations'); }
public function down(Database $db) { $db->selectCollection('Monkey')->createQueryBuilder()->update(array(), array())->multiple(true)->field('isHappy')->set(false)->getQuery()->execute(); }
public function up(Database $db) { $endOf2013 = new \MongoDate(strtotime('2013-12-31T23:23:59Z')); $db->selectCollection('Log')->remove(['date' => ['$lte' => $endOf2013]], ['multi' => true]); }
protected function isWorkspaceAvailable() { $workspaceColl = $this->db->selectCollection(self::COLLNAME_WORKSPACES); $qb = $workspaceColl->createQueryBuilder()->field('_id')->equals($this->workspaceId); $workspace = $qb->getQuery()->getSingleResult(); return null !== $workspace; }
public function down(Database $db) { $db->selectCollection('Node')->createQueryBuilder()->update()->field('syndications')->unsetField()->exists(true)->getQuery()->execute(); }
/** * This postUp is not required * I use it to demonstrate the analyzer */ public function postUp(Database $db) { $testA = $db->selectCollection('test_a'); $testA->drop(); }
/** * @see EntityDocumentSaver::saveEntityDocument */ public function saveEntityDocument(EntityDocument $entityDocument) { $this->database->selectCollection($entityDocument->getType())->upsert($this->buildGetEntityForIdQuery($entityDocument->getId()), $this->documentBuilder->buildDocumentForEntity($entityDocument)); }
public function down(Database $db) { $agencies = $db->selectCollection('Agency'); $agencies->createQueryBuilder()->update()->multiple(true)->field('internal')->unsetField()->exists(true)->getQuery()->execute(); $this->analyze($agencies); }
public function down(Database $db) { $history = $this->createHistory(self::OLD_RATE, self::NEW_RATE); $db->selectCollection('Item')->update(['vatTaxRate' => self::NEW_RATE], ['$set' => ['vatTaxRate' => self::OLD_RATE], '$push' => ['history' => $history]], ['multiple' => true]); }