Module: kamailio
Branch: 5.1
Commit: 49dee7f498e1001ce3e29c1691a7ec322392baca
URL:
https://github.com/kamailio/kamailio/commit/49dee7f498e1001ce3e29c1691a7ec3…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-03-01T15:52:38+01:00
db_mongodb: use projection iterator to convert bson for result
(cherry picked from commit 899ab355fb58e22eaa02336e9b5b1f2f53dba375)
---
Modified: src/modules/db_mongodb/mongodb_dbase.c
---
Diff:
https://github.com/kamailio/kamailio/commit/49dee7f498e1001ce3e29c1691a7ec3…
Patch:
https://github.com/kamailio/kamailio/commit/49dee7f498e1001ce3e29c1691a7ec3…
---
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");