+ BSON_APPEND_UTF8(&subarray, key, DS_TYPE_TO_STRING(ds->ds[i].type));
+ }
+ bson_append_array_end(ret, &subarray); /* }}} dstypes */
+
+ BSON_APPEND_ARRAY_BEGIN(ret, "dsnames", &subarray); /* {{{ */
+ for (size_t i = 0; i < ds->ds_num; i++) {
+ char key[16];
+
+ snprintf(key, sizeof(key), "%" PRIsz, i);
+ BSON_APPEND_UTF8(&subarray, key, ds->ds[i].name);
+ }
+ bson_append_array_end(ret, &subarray); /* }}} dsnames */
+
+ sfree(rates);
+
+ size_t error_location;
+ if (!bson_validate(ret, BSON_VALIDATE_UTF8, &error_location)) {
+ ERROR("write_mongodb plugin: Error in generated BSON document "
+ "at byte %" PRIsz,
+ error_location);
+ bson_destroy(ret);
+ return NULL;