Definition
New in version 8.3.
Syntax
$subtype has the following syntax:
{ $subtype: <expression> }
The <expression> can be any valid expression that contains a subtype.
Note
In MongoDB 8.3, the only expression that contains a subtype is a
BinData expression.
Behavior
Null or Missing Values
$subtype operations on null or missing values return null.
Unaccepted Expressions
$subtype operations on expressions that do not have a subtype return an
error.
BinData Output
$subtype operations on BinData expressions return
the binary subtype of the expression. For more information, see
Binary Subtypes.
Example
Use the BinData() constructor to create a bdata variable.
var bdata = BinData(0, "gf1UcxdHTJ2HQ/EGQrO7mQ==")
The following operation outputs the subtype of the bdata object:
{ $subtype: bdata }
The expression returns 0.