* BsonDocumentValueCountKeys returns the number of keys in a given bson document value. * "value" should be of type BSON_TYPE_ARRAY or BSON_TYPE_DOCUMENT */
| 88 | * "value" should be of type BSON_TYPE_ARRAY or BSON_TYPE_DOCUMENT |
| 89 | */ |
| 90 | int |
| 91 | BsonDocumentValueCountKeys(const bson_value_t *value) |
| 92 | { |
| 93 | if (value->value_type != BSON_TYPE_ARRAY && value->value_type != BSON_TYPE_DOCUMENT) |
| 94 | { |
| 95 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 96 | errmsg("Value must be either an array type or a document type"))); |
| 97 | } |
| 98 | bson_t bson; |
| 99 | if (!bson_init_static(&bson, value->value.v_doc.data, |
| 100 | value->value.v_doc.data_len)) |
| 101 | { |
| 102 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 103 | errmsg("invalid input syntax for BSON"))); |
| 104 | } |
| 105 | |
| 106 | return bson_count_keys(&bson); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /* |
no outgoing calls
no test coverage detected