laravel-mongodb - Issue #3483: `where('field', 'elemMatch', [...])` returns empty results in v5.x (worked in v4.x)

    • Type: Question
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      NovzChrono has created Issue #3483: `where('field', 'elemMatch', [...])` returns empty results in v5.x (worked in v4.x) in laravel-mongodb. This Jira ticket was filed by GromNaN

      Issue Text:

        1. Environment
      • mongodb/laravel-mongodb: ^5.6
      • laravel/framework: ^11.9
      • PHP: 8.3
      • MongoDB server: 7.0.12
        1. Description
          After upgrading from ^4.5 to ^5.6, queries using the `elemMatch` operator
          via `where()` return empty results even though matching documents exist.
        1. Code
          ```php
          // Returns empty in v5.6, worked in v4.5
          $module = Module::whereNull('deleted_at')
          ->where('timeline', 'elemMatch', [
          'direction.id' => '694a6f1b2c74d64f8f02a1fb',
          'role.id' => '694a6f1a2c74d64f8f02a1f1',
          'status' => 'enable',
          ])
          ->where('code', 'approvFirst')
          ->first();
          Document in MongoDB

      {
      "code": "approvFirst",
      "timeline": [
      {
      "direction":

      { "id": "694a6f1b2c74d64f8f02a1fb" }

      ,
      "role":

      { "id": "694a6f1a2c74d64f8f02a1f1" }

      ,
      "status": "enable"
      }
      ]
      }
      Expected
      Document is returned.

      Actual
      null / empty collection.

      Notes
      Dot-notation keys inside the elemMatch condition (direction.id, role.id)
      may not be handled correctly in v5.x.

            Assignee:
            Andreas Braun
            Reporter:
            TPM Jira Automations Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: