Skip to content

Commit 357d633

Browse files
-added option to disable converting bson object to array on aggregate results
-added option to disable converting _id in to id automatically
1 parent 9973195 commit 357d633

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Eloquent/Builder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ public function raw($value = null)
181181

182182
// Convert MongoCursor results to a collection of models.
183183
if ($results instanceof CursorInterface) {
184-
$results->setTypeMap(['root' => 'array', 'document' => 'array', 'array' => 'array']);
184+
if(!config('database.connections.mongodb.options.AggregateCollectionArray')){
185+
$results->setTypeMap(['root' => 'array', 'document' => 'array', 'array' => 'array']);
186+
}
187+
185188
$results = $this->query->aliasIdForResult(iterator_to_array($results));
186189

187190
return $this->model->hydrate($results);

src/Query/Builder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,9 @@ private function aliasIdForQuery(array $values): array
16671667
*/
16681668
public function aliasIdForResult(array|object $values): array|object
16691669
{
1670+
if(config('database.connections.mongodb.options.DisableAliasIdForResult')){
1671+
return $values;
1672+
}
16701673
if (is_array($values)) {
16711674
if (array_key_exists('_id', $values) && ! array_key_exists('id', $values)) {
16721675
$values['id'] = $values['_id'];

0 commit comments

Comments
 (0)