diff --git a/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c b/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c index 81d3b22386..74a4c5df8e 100644 --- a/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c +++ b/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c @@ -69,6 +69,26 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_mongodb_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_mongodb_shutdown); SWITCH_MODULE_DEFINITION(mod_cdr_mongodb, mod_cdr_mongodb_load, mod_cdr_mongodb_shutdown, NULL); +static void bson_append_value(bson *cdr, char *name, char *val) +{ + //Check the variable and insert it as int, long int or string depending on it's value + char* endptr; + long int lintValue = strtol(val, &endptr, 10); + + if (!*endptr){ + int intValue = lintValue; + if(intValue == lintValue){ + bson_append_int(cdr, name, intValue); + }else{ + bson_append_long(cdr, name, lintValue); + } + } else { + bson_append_string(cdr, name, val); + } + +} + + static void set_bson_profile_data(bson *b, switch_caller_profile_t *caller_profile) { bson_append_string(b, "username", caller_profile->username); @@ -162,7 +182,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) if ((hi = switch_channel_variable_first(channel))) { for (; hi; hi = hi->next) { if (!zstr(hi->name) && !zstr(hi->value)) { - bson_append_string(&cdr, hi->name, hi->value); + bson_append_value(&cdr, hi->name, hi->value); } } switch_channel_variable_last(channel);