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

Provide "is subset" array functionality in query predicate language

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Querying
    • None
    • Query
    • 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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: