From MongoDB 4.4, you can use the $binarySize
aggregation pipeline operator to return the size of a given string or binary data value’s content in bytes.
It accepts any valid expression as long as it resolves to either a string or binary data value. The argument can also be null
, in which case, $binarySize
returns null
.