Module: kamailio
Branch: 5.1
Commit: ece17deeba435ed19c16fc2a227d351fd6013f86
URL:
https://github.com/kamailio/kamailio/commit/ece17deeba435ed19c16fc2a227d351…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-03-01T15:52:29+01:00
db_mongodb: iterate on projection fields for matching cols in result
(cherry picked from commit aab4f5db964bf1980729ed8b7770f550bb86b72b)
---
Modified: src/modules/db_mongodb/mongodb_dbase.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ece17deeba435ed19c16fc2a227d351…
Patch:
https://github.com/kamailio/kamailio/commit/ece17deeba435ed19c16fc2a227d351…
---
diff --git a/src/modules/db_mongodb/mongodb_dbase.c
b/src/modules/db_mongodb/mongodb_dbase.c
index 1e790b8b9d..aba482d352 100644
--- a/src/modules/db_mongodb/mongodb_dbase.c
+++ b/src/modules/db_mongodb/mongodb_dbase.c
@@ -316,10 +316,12 @@ int db_mongodb_get_columns(const db1_con_t* _h, db1_res_t* _r)
int col;
db_mongodb_result_t *mgres;
bson_iter_t riter;
+ bson_iter_t titer;
bson_iter_t citer;
bson_t *cdoc;
const char *colname;
bson_type_t coltype;
+ int cdocproj;
if ((!_h) || (!_r)) {
LM_ERR("invalid parameter\n");
@@ -338,8 +340,10 @@ int db_mongodb_get_columns(const db1_con_t* _h, db1_res_t* _r)
return -1;
}
cdoc = mgres->rdoc;
+ cdocproj = 0;
} else {
cdoc = mgres->colsdoc;
+ cdocproj = 1;
}
RES_COL_N(_r) = mgres->nrcols;
if (!RES_COL_N(_r)) {
@@ -355,9 +359,25 @@ int db_mongodb_get_columns(const db1_con_t* _h, db1_res_t* _r)
return -3;
}
- if (!bson_iter_init (&citer, cdoc)) {
- LM_ERR("failed to initialize columns iterator\n");
- return -3;
+ if(cdocproj == 1) {
+ 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;
+ }
+ } else {
+ if (!bson_iter_init (&citer, cdoc)) {
+ LM_ERR("failed to initialize columns iterator\n");
+ return -3;
+ }
}
if(mgres->colsdoc) {
if (!bson_iter_init (&riter, mgres->rdoc)) {