> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# $subtype (expression operator)

## Definition

**New in version 8.3**

Returns the subtype of a given value as an integer.

## Syntax

[`$subtype`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype.md#mongodb-expression-exp.-subtype) has the following syntax:

```javascript
{ $subtype: <expression> }
```

The `<expression>` can be any valid [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) that contains a subtype.

**Note:**

In MongoDB 8.3, the only expression that contains a subtype is a [`BinData`](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json-v1.md#mongodb-bsontype-data_binary) 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`](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json-v1.md#mongodb-bsontype-data_binary) expressions return the binary subtype of the expression. For more information, see [Binary Subtypes.](https://www.mongodb.com/docs/manual/reference/method/bindata.md#std-label-binData-subtype)

## Example

Use the [`BinData()`](https://www.mongodb.com/docs/manual/reference/method/bindata.md#mongodb-method-BinData) constructor to create a `bdata` variable.

```javascript
var bdata = BinData(0, "gf1UcxdHTJ2HQ/EGQrO7mQ==")
```

The following operation outputs the subtype of the bdata object:

```javascript
{ $subtype: bdata }
```

The expression returns `0`.

## Learn More

- [BinData() (mongosh method)](https://www.mongodb.com/docs/manual/reference/method/bindata.md#std-label-server-binData-method)

- [Binary.createFromBase64() (mongosh method)](https://www.mongodb.com/docs/manual/reference/method/binary.createfrombase64.md#std-label-Binary.createFromBase64)
