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

$pullAll API is not consistent with $pull API

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.4.0
    • Component/s: Usability
    • None

      I'm trying to pull multiple hashes from an array but only know the value of one of the hash keys. I expected $pullAll to work in a similar manner to $pull but got an error message instead.

      use temp
      db.dropDatabase()

      db.bands.save({
      name: 'The Beatles',
      members: [

      {name: 'John', instrument: 'guitar'}

      ,

      {name: 'Paul', instrument: 'bass'}

      ,

      {name: 'George', instrument: 'guitar'}

      ,

      {name: 'Ringo', instrument: 'drums'}

      ]
      })

      db.bands.update({}, {$pull: {members:

      {instrument: 'drums'}

      }})
      // Ringo is removed

      db.bands.update({}, {$pullAll: {members:

      {instrument: ['guitar', 'bass']}

      }})
      // John, Paul, and George should be removed but get this error instead:
      // Modifier $pushAll/pullAll allowed for arrays only

      db.bands.update({}, {
      $pullAll: {members: [

      {name: 'John', instrument: 'guitar'}

      ,

      {name: 'Paul', instrument: 'bass'}

      ,

      {name: 'George', instrument: 'guitar'}

      ]}
      })
      // It works if you specify the EXACT hash

      db.bands.find()

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            msheakoski Michael Sheakoski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: