Skip to content

Cast MongoCursor result to Collection of Model  #2196

Open
@Giacomo92

Description

@Giacomo92

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions