Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-11803

Docs for SERVER-35454: Query system does not fail cleanly for $type:0 when an index is available


      The ability to use {$type: 0} was a misfeature that was never correctly implemented. Since 0 is the "EOO" type code, this query could have been used to find documents in which a particular field is missing. However, the correct and fully supported way to do this is {$exists:false}. The {$type:0} predicate never worked if the field was indexed. Furthermore, we have never permitted something like {$type: "missing"}.

      There is a possibility that a small body of users had written queries that depended on this misfeature. 4.2 completely removes support for it. We should probably document that {$type:0} and {$type:"missing"} are not supported, and that {$exists:false} should be used instead.

      Scope of changes:

      We don't mention type 0. So, changes will be minimal where related to using type/exists for field existence check.

      • 4.2-compat
      • footnote in $type and $exists
      • note in /tutorial/query-for-null-fields

      Impact to other docs outside of this product:




      Engineering Ticket Description:

      The $type query predicate should not support type code 0, as this is used internally for the "missing" or "EOO" BSON type. The system should reject an attempt to use $type:0 with a clear error message. Instead, when an index is available for use by the $type predicate, the server returns an internal error message such as the following:

      	"ok" : 0,
      	"errmsg" : "type not supported for appendMinElementForType",
      	"code" : 10061,
      	"codeName" : "Location10061"

      Users who wish to check for existence of a field should instead use $exists:false.

            kay.kim@mongodb.com Kay Kim (Inactive)
            kay.kim@mongodb.com Kay Kim (Inactive)
            0 Vote for this issue
            1 Start watching this issue

              5 years, 29 weeks, 4 days ago