[SERVER-20718] $type should take an array of types to match against Created: 01/Oct/15  Updated: 06/Dec/22  Resolved: 29/Aug/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: David Golden Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-30245 Extend JSON Schema parser to handle t... Closed
Related
is related to SERVER-30191 Add JSON Schema support for document ... Closed
Assigned Teams:
Query
Participants:

 Description   

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).



 Comments   
Comment by David Storch [ 29/Aug/17 ]

This was implemented in SERVER-30245, since it made sense to do as part of adding JSON Schema support to MongoDB (see SERVER-30191). I am marking this ticket as a duplicate in order to reflect the new state of affairs.

Comment by David Storch [ 26/Oct/15 ]

We would like to keep the predicate language small. Instead of adding $or-like functionality to $type, we think it makes sense to require use of $or. Closing as Won't Fix.

Generated at Thu Feb 08 03:55:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.