MongoHybrid\Mongo::find PHP Method

find() public method

public find ( $collection, $options = [] )
    public function find($collection, $options = [])
    {
        $filter = isset($options["filter"]) && $options["filter"] ? $options["filter"] : [];
        $fields = isset($options["fields"]) && $options["fields"] ? $options["fields"] : [];
        $limit = isset($options["limit"]) && $options["limit"] ? $options["limit"] : null;
        $sort = isset($options["sort"]) && $options["sort"] ? $options["sort"] : null;
        $skip = isset($options["skip"]) && $options["skip"] ? $options["skip"] : null;
        if ($filter && isset($filter["_id"])) {
            $filter["_id"] = new \MongoId($filter["_id"]);
        }
        $cursor = $this->getCollection($collection)->find($filter, $fields);
        if ($limit) {
            $cursor->limit($limit);
        }
        if ($sort) {
            $cursor->sort($sort);
        }
        if ($skip) {
            $cursor->skip($skip);
        }
        if ($cursor->count()) {
            $docs = array_values(iterator_to_array($cursor));
            foreach ($docs as &$doc) {
                if (isset($doc["_id"])) {
                    $doc["_id"] = (string) $doc["_id"];
                }
            }
        } else {
            $docs = [];
        }
        $resultSet = new ResultSet($this, $docs);
        return $resultSet;
    }