Important
New database features are no longer connected to engine versions; features are now enabled independently during scheduled update windows, and “major” and “minor” releases no longer exist in Helios. Please visit the release notes to view the latest features available in your database clusters.
BSON_ LENGTH
On this page
The BSON_ function 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: