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

$elemMatch object can treat '0' as an array index

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • Query 2019-11-04

       

      Consider following document:

      {
        items: [
          [1, [2]],
          [2, [1]],
          [3, [1]],
          [2, [1]],
        ]
      }
      
      

      I want to remove all items which their 0 index is 2.

      db.col.updateMany(
          {},
          {
              $pull: {
                  'items': {
                      0: 2
                  }
              }
          }
      )
      

      this does nothing.

      db.col.update(
          {},
          {
              $pull: {
                  'items': {
                      $elemMatch: {
                          '0': 2
                      }
                  }
              }
          }
      )
      

      this oddly removes first item of items.

      db.col.updateMany(
          {},
          {
              $pull: {
                  'items': {
                      $elemMatch: {
                          $in: [2]
                      }
                  }
              }
          }
      )
      

      this works as expected.

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            rahbari@gmail.com Ali Rahbari
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: