laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

Cast MongoCursor result to Collection of Model

Open Giacomo92 opened this issue 4 years ago • 1 comments

Hi, I want to know if there is a way to cast a Mongo Cursor instance from a raw query in to a Collection of Model.

DB::collection('test')->raw()->aggregate( [ ['$match' => ["status" => 'published' ]] ] );

Schermata 2021-02-06 alle 10 27 40

I saw the method toArray(); that cast Mongo Cursor instance into an array

DB::collection('test')->raw()->aggregate( [ ['$match' => ["status" => 'published' ]] ] )->toArray();

Schermata 2021-02-06 alle 10 31 08

So now I need to cast each BSONDocument to a Model.

I want know if there is an efficiente way to do so. I think this is exactly what the package does under the hood

Thanks

Giacomo92 avatar Feb 06 '21 09:02 Giacomo92

I think that PR can will resolve this issue

Smolevich avatar Feb 08 '21 06:02 Smolevich