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

Provide "is subset" array functionality in query predicate language

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query
    • Fully Compatible

      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" ] } } )
      > 
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            4 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: