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

Should have an $* array-key-wildcard operator

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      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

            Votes:
            9 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: