Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1248

Should have an $* array-key-wildcard operator

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      As far as I can tell there is no way to find an object containing a value in a subarray if you do not know the exact array-key path, so if the following were a collection of orders you cannot find all orders by unit ID without modifying the schema:

      array(
      '_id' => 213,
      'units' = array(
      0 => array('id' => 5, 'color' => 'red'),
      1 => array('id' => 3, 'color' => 'blue'),
      2 => array('id' => 8, 'color' => 'polka dot'),
      3 => array('id' => 9, 'color' => 'green')
      )
      );

      array(
      '_id' => 456,
      'units' = array(
      0 => array('id' => 8, 'color' => 'purple'),
      1 => array('id' => 2, 'color' => 'yellow')
      )
      );

      We should be able to do something like:

      $find = array('units.$*.id' => 8);
      $col->find($find);

      Assuming $* would be a wildcard operator that covers any key within the array

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                9 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: