Find an item of the data from the collection

@param string $collectionName
@param array  $criteria
@param array  $fields
490299
public function findFirst($collectionName, array $criteria = [], array $fields = []) {
		$collection = $this->getCollection($collectionName);
		
		if ($this->_profilerEnabled) {
			$message = 'db.' . $collectionName . '.findOne(';

			if (empty($criteria)) {
				$message .= ');';
			} else {
				$message .= json_encode($criteria) . ');';
			}

			$event = $this->getProfiler()->startRead($message);
		}

		$result = $collection->findOne($criteria, $fields);

		if ($this->_profilerEnabled) {
			$event->stopSuccess();
		}

		return $result;
	}
1003018
protected function find(string $indexedFieldName, $fieldValue)
    {
        $fieldIndex = $this->getIndex($indexedFieldName);

        return isset($fieldIndex[$fieldValue]) ? $fieldIndex[$fieldValue] : null;
    }
409304
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $criteria = array_merge($criteria, array("deleted" => false));

        return parent::findBy($criteria, $orderBy, $limit, $offset);
    }
427232
public function findBy(array $criteria)
    {
        $found = [];
        foreach ($this->getCollection()->all() as $template) {
            foreach ($criteria as $criterium => $value) {
                $method = 'get'.ucfirst(strtolower($criterium));
                if (!method_exists($template, $method)) {
                    continue;
                }
                if ($template->$method() !== $value) {
                    continue 2;
                }
            }

            $found[] = $template;
        }

        return $found;
    }
276174
public function dropIndexes($collectionName, $indexes)
    {
        $this->document = $this->db->getQueryBuilder()->dropIndexes($collectionName, $indexes);

        return current($this->execute()->toArray());
    }
849499
public function applySimpleFilter(CollectionFinderInterface $finder, $fieldName)
    {
        $filterValue = $this->state->get("filter." . $fieldName, null);
        if (!empty($filterValue)) {
            $finder = $finder->with($fieldName, Operator::EQUAL, $filterValue);
        }

        return $finder;
    }
1180342
public function seeElementIsObject($collection, $criteria = [], $elementToCheck = null)
    {
        $collection = $this->driver->getDbh()->selectCollection($collection);

        $res = $collection->count(
            array_merge(
                $criteria,
                [
                    $elementToCheck => ['$exists' => true],
                    '$where' => "! Array.isArray(this.{$elementToCheck}) && isObject(this.{$elementToCheck})"
                ]
            )
        );
        if ($res > 1) {
            throw new \PHPUnit\Framework\ExpectationFailedException(
                'Error: you should test against a single element criteria when asserting that elementIsObject'
            );
        }
        \PHPUnit\Framework\Assert::assertEquals(1, $res, 'Specified element is not a Mongo Object');
    }
1061748
public function getCollection($collectionName) {
		if (! isset($this->collections[$collectionName])) {
			$this->collections[$collectionName] = $this->getDatabase()->selectCollection($collectionName);
		}

		return $this->collections[$collectionName];
	}
734494
public function scanCollection($collection, $fields)
    {
        $fields = (array) $fields;
        foreach ($collection as $item) {
            $this->collectIdsFromItem($item, $fields);
        }

        return $this;
    }
744365
public function findBy(array $criteria = [])
    {
        $data = $this->storage->findBy($this->schema, $this->typeSchema->name(), $criteria);

        if (count($data) === 0 || !array_key_exists('id', $data)) {
            return null;
        }

        return $this->hydrator->hydrate($this->typeSchema, $data);
    }
1098349
public static function findAllEntitiesByCriteria(array $criteria = [], array $exclude = []): array
    {
        $class = static::class;

        /** @var EntityRepository $obj_collection */
        $obj_collection = new $class();

        foreach ($criteria as $k => $v) {
            $obj_collection->addSimpleWhereField($k, $v);
        }

        foreach ($exclude as $k => $v) {
            $obj_collection->addWhereFieldIsNot($k, $v);
        }

        return $obj_collection->getAsArrayOfObjects();
    }
164850
final public static function findAll(Api\Client $client, array $criteria = []) : Api\Collection
    {
        $filters = [
            'format' => [
                [
                    'in',
                    [
                        'comic', 'hardcover', 'trade paperback', 'magazine', 'digest',
                        'graphic novel', 'digital comic', 'infinite comic',
                    ]
                ],
            ],
            'formatType' => [['in', ['comic', 'collection']]],
            'noVariants' => [['bool'], ['bool-convert']],
            'dateDescriptor' => [['in', ['lastWeek', 'thisWeek', 'nextWeek', 'thisMonth']]],
            'fromDate' => [['date', true]],
            'toDate' => [['date', true]],
            'hasDigitalIssue' => [['bool'], ['bool-convert']],
            'modifiedSince' => [['date', true], ['date-format', 'c']],
            'creators' => [['ofScalars', [['uint']]], ['implode', ',']],
            'characters' => [['ofScalars', [['uint']]], ['implode', ',']],
            'series' => [['ofScalars', [['uint']]], ['implode', ',']],
            'events' => [['ofScalars', [['uint']]], ['implode', ',']],
            'stories' => [['ofScalars', [['uint']]], ['implode', ',']],
            'sharedAppearances' => [['ofScalars', [['uint']]], ['implode', ',']],
            'collaborators' => [['ofScalars', [['uint']]], ['implode', ',']],
            'orderBy' => [
                [
                    'in',
                    [
                        'focDate', 'onsaleDate', 'title', 'issueNumber', 'modified',
                        '-focDate', '-onsaleDate', '-title', '-issueNumber', '-modified',
                    ],
                ]
            ],

        ];

        list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria);
        Util::ensure(true, $success, $error);
        $toDate = Util\Arrays::get($filteredCriteria, 'toDate');
        $fromDate = Util\Arrays::get($filteredCriteria, 'fromDate');
        if ($toDate !== null && $fromDate !== null) {
            unset($filteredCriteria['toDate'], $filteredCriteria['fromDate']);
            $filteredCriteria['dateRange'] = "{$fromDate->format('c')},{$toDate->format('c')}";
        }

        return new Api\Collection($client, self::API_RESOURCE, $filteredCriteria);
    }
385609
public function setCollectionName(string $collectionName)
    {
        if ($this->nested) {
            throw new LogicException(
                sprintf(
                    'Collection name cannot be set for nested document class "%s".',
                    $this->documentClass
                )
            );
        }

        $this->collectionName = $collectionName;

        return $this;
    }
29111
public function find($collectionName, $condition, $options = [])
    {
        $queryBuilder = $this->db->getQueryBuilder();

        $this->document = $queryBuilder->buildCondition($condition);

        if (isset($options['projection'])) {
            $options['projection'] = $queryBuilder->buildSelectFields($options['projection']);
        }

        if (isset($options['sort'])) {
            $options['sort'] = $queryBuilder->buildSortFields($options['sort']);
        }

        if (array_key_exists('limit', $options)) {
            if ($options['limit'] === null || !ctype_digit((string) $options['limit'])) {
                unset($options['limit']);
            } else {
                $options['limit'] = (int)$options['limit'];
            }
        }
        if (array_key_exists('skip', $options)) {
            if ($options['skip'] === null || !ctype_digit((string) $options['skip'])) {
                unset($options['skip']);
            } else {
                $options['skip'] = (int)$options['skip'];
            }
        }

        return $this->query($collectionName, $options);
    }
927895
public function removeCriteria($criteriaName = '')
    {
        if (!empty($criteriaName)) {
            $this->stack = $this->stack->filter(function (CriteriaInterface $criteria) use ($criteriaName) {
                return !is_a($criteria, $criteriaName);
            });

            return true;
        }

        $this->stack = new Collection();

        return true;
    }
647437
public function getIterator($criteria = [], array $fields = []) {
		$criteriaNormalized = $this->normalizeCriteria($criteria);
		
		$mongoCursor = $this->getAdapter()->find(
			$this->getTableName(),
			$criteriaNormalized,
			$fields
		);
		
		if ($criteria instanceof Criteria) {
			$this->applyCriteriaToCursor($criteria, $mongoCursor);
		}
		
		return $this->createIterator($mongoCursor);
	}
693225
public function findBySha1AndCollectionName($sha1Hash, $collectionName)
    {
        $query = $this->createQuery();
        $query->matching(
            $query->logicalAnd(
                $query->equals('sha1', $sha1Hash),
                $query->equals('collectionName', $collectionName)
            )
        );
        $resources = $query->execute()->toArray();
        foreach ($this->addedResources as $importedResource) {
            if ($importedResource->getSha1() === $sha1Hash && $importedResource->getCollectionName() === $collectionName) {
                $resources[] = $importedResource;
            }
        }

        return $resources;
    }