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

$type should take an array of types to match against

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query

      For document validation to allow multiple acceptable types for a field, one must nest a verbose $or expression in the validator like this:

      {
          "$or" : [
              { "views" : { "$type" : 16 } },
              { "views" : { "$type" : 18 } }
          ]
      }
      

      It would be much easier to use $type if it could optionally take an array, which would be treated like $in and match any of the elements of the array.

      The expression above would thus simplify to this:

      { "views" : { "$type" : [16, 18] } }
      

      When such multi-type constraints have to be applied to many fields, validators would be much more succinct, making them easier to write (and read).

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: