Skip to content

Wrong casting in $lookup relations #2505

Open
@Siebov

Description

@Siebov
  • Laravel-mongodb Version: 3.8.5
  • PHP Version: 8.0
  • Database Driver & Version:
    4.2.3

Description:

I'm using raw query to get data from DB.
There is a few $lookup I use. One for rounds collection another one for the users.

'$lookup' => [
                'from' => 'users',
                'localField' => 'user_mongo_id',
                'foreignField' => '_id',
                'as' => 'user'            
]

...

'$lookup' => [
                'from' => 'rounds',
                'localField' => 'round_mongo_id',
                'foreignField' => '_id',
                'as' => 'proposal_round'            
]

Parent model has 1 round and 1 user. (1 to 1 relation)
For some reason user casts differently from round:

  • Round relation is an object with string _id and stringified dates.
  • User is an array of 1 single object, with { _id: $oid: '.....'} and dates like

"created_at": { "$date": { "$numberLong": "1659863891000" } }

User:

image

Round:

image

Expected behaviour

I expect user to be an object (not array of objects) with stringified properties _id and dates (not displayed as an objects).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions