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

XMLWordPrintableJSON

    • Type: Question
    • Resolution: Works as Designed
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • 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:
            Jérôme Tamarelle
            Reporter:
            TPM Jira Automations Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: