Skip to content

Impossible to query for _id using whereRaw #2255

@galzetta

Description

@galzetta
  • Laravel-mongodb Version: 3.2.3
  • PHP Version: 7.3
  • Database Driver & Version: Mongo DB 4.4, ext-mongo >= 1.9

Description:

Steps to reproduce

  1. Try to query something using Class::query()->whereRaw(['_id' => 'some-value']) or Class::query()->whereRaw(['_id' => ['$eq' => 'some-value']])

Expected behaviour

The query should return exactly the same results as Class:query()->where('_id', 'some-value')

Actual behaviour

No result is returned


In my situation I have some subscriptions and some logic that defines general rules for when a customer can see a certain subscription type. However I also need to implement an override (basically customer service wants to specify that user X can see subscription type Y even though this doesn't follow the standard rules). To do this I want to write a query like:

->whereRaw([
    '$or' => [$set_of_standard_rules, ['_id' => ['$in' => $user_overrides]]]
])

However the _id part is never matched, even when using the basic query whereRaw(['_id' => 'some-value']) or whereRaw(['_id' => ['$eq' => 'some-value']]).

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