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

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Optimization
    • Query 2019-11-04

    Description

       

      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.

       

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            rahbari@gmail.com Ali Rahbari
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: