Module: kamailio
Branch: master
Commit: 899ab355fb58e22eaa02336e9b5b1f2f53dba375
URL:
https://github.com/kamailio/kamailio/commit/899ab355fb58e22eaa02336e9b5b1f2…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-03-01T14:28:47+01:00
db_mongodb: use projection iterator to convert bson for result
---
Modified: src/modules/db_mongodb/mongodb_dbase.c
---
Diff:
https://github.com/kamailio/kamailio/commit/899ab355fb58e22eaa02336e9b5b1f2…
Patch:
https://github.com/kamailio/kamailio/commit/899ab355fb58e22eaa02336e9b5b1f2…
---
diff --git a/src/modules/db_mongodb/mongodb_dbase.c
b/src/modules/db_mongodb/mongodb_dbase.c
index aba482d352..b1c9ac2bb7 100644
--- a/src/modules/db_mongodb/mongodb_dbase.c
+++ b/src/modules/db_mongodb/mongodb_dbase.c
@@ -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;
@@ -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");