BSON_ LENGTH
On this page
Returns the number of keys present in the BSON object or array.
Syntax
BSON_LENGTH(<value>)
Argument
<value>
: A valid BSON object or array, or an expression that evaluates to a valid BSON object or array.
Return Type
A number.
Remarks
Returns NULL
if the input value is one of the following:
-
An invalid BSON type
-
A BSON type other than a document or an array
-
A
NULL
Examples
Note: The following examples explicitly cast string to BSON for clarity.
SELECT BSON_LENGTH('{"a":1, "b":2, "c":"abc"}':>BSON) AS Length;
+--------+
| Length |
+--------+
| 3 |
+--------+
SELECT BSON_LENGTH('[1, true, null, [7,8,9], "abc"]':>BSON) AS Length;
+--------+
| Length |
+--------+
| 5 |
+--------+
SELECT BSON_LENGTH('null':>BSON) AS Length;
+--------+
| Length |
+--------+
| NULL |
+--------+
Last modified: April 2, 2024