Problem: Using "yiisoft\yii2\rest" on a mongodb collection results in and empty object being displayed "{}".
Cause: MongoId object with "$id" returned in result set.
Suggested Solution: Modify "yiisoft\yii2\data\ActiveDataProvider" class as follows:
/**
* @inheritdoc
*/
protected function prepareModels()
{
if (!$this->query instanceof QueryInterface) {
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
}
$query = clone $this->query;
if (($pagination = $this->getPagination()) !== false) {
$pagination->totalCount = $this->getTotalCount();
$query->limit($pagination->getLimit())->offset($pagination->getOffset());
}
if (($sort = $this->getSort()) !== false) {
$query->addOrderBy($sort->getOrders());
}
/* START CHANGE */
$results = $query->all($this->db);
foreach ($results as $result) {
if(get_class($result['_id']) === "MongoId") {
$result['_id'] = (string)$result['_id'];
}
}
return $results;
/* END CHANGE */
}