Skip to content

Commit

Permalink
db_mongodb: use projection iterator to convert bson for result
Browse files Browse the repository at this point in the history
(cherry picked from commit 899ab35)
(cherry picked from commit 49dee7f)
  • Loading branch information
miconda committed Apr 25, 2018
1 parent 74f7515 commit 79e2934
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/modules/db_mongodb/mongodb_dbase.c
Expand Up @@ -506,6 +506,7 @@ static int db_mongodb_convert_bson(const db1_con_t* _h, db1_res_t* _r,
const char *colname;
bson_type_t coltype;
bson_iter_t riter;
bson_iter_t titer;
bson_iter_t citer;
bson_iter_t *piter;
db_val_t* dval;
Expand All @@ -520,14 +521,27 @@ static int db_mongodb_convert_bson(const db1_con_t* _h, db1_res_t* _r,
}
if(mgres->colsdoc==NULL) {
cdoc = (bson_t*)_rdoc;
if (!bson_iter_init (&citer, cdoc)) {
LM_ERR("failed to initialize columns iterator\n");
return -3;
}
} else {
cdoc = (bson_t*)mgres->colsdoc;
if (!bson_iter_init (&titer, cdoc)) {
LM_ERR("failed to initialize columns iterator\n");
return -3;
}
if(!bson_iter_find(&titer, "projection")
|| !BSON_ITER_HOLDS_DOCUMENT (&titer)) {
LM_ERR("failed to find projection field\n");
return -3;
}
if(!bson_iter_recurse (&titer, &citer)) {
LM_ERR("failed to init projection iterator\n");
return -3;
}
}

if (!bson_iter_init (&citer, cdoc)) {
LM_ERR("failed to initialize columns iterator\n");
return -3;
}
if(mgres->colsdoc) {
if (!bson_iter_init (&riter, _rdoc)) {
LM_ERR("failed to initialize result iterator\n");
Expand Down

0 comments on commit 79e2934

Please sign in to comment.