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

Provide "is subset" array functionality in query predicate language

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible

      Description

      Summary

      $only would select the document where the queried field is an array that only contains the specified values. (If the queried field isn't an array, then the operator is identical to $in.)

      Example

      > db.foo.drop()
      > db.foo.insert( { a: [ "a", "b" ] } )
      > db.foo.insert( { a: [ "a", "d" ] } )
      > db.foo.insert( { a: [ "d", "e" ] } )
      > db.foo.find( { a: { $in: [ "a", "b", "c" ] } } )
      { a: [ "a", "b" ] }
      { a: [ "a", "d" ] }
      > db.foo.find( { a: { $only: [ "a", "b", "c" ] } } )
      { a: [ "a", "b" ] }
      

      More details

      $nin already has semantics of checking all elements in the document array to make sure none of them are in the supplied array. This suggestion is just like that, except it should check that every element is in the target array (instead of is not in the target array as $nin does). i.e. compare the above to:

      > db.foo.find( { a: { $nin: [ "a", "b", "c" ] } } )
      { a: [ "d", "e" ] }
      

      $all is not what I'm looking for:

      > db.foo.find( { a: { $all: [ "a", "b", "c" ] } } )
      > 
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-server-query Backlog - Query Team
              Reporter:
              kevin.pulo Kevin Pulo
              Participants:
              Votes:
              4 Vote for this issue
              Watchers:
              14 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: