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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: None
    • Labels:
      None

      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

            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated: