[sr-dev] git:5.1:cc92737d: db_mongodb: create projection field to set the list of returned column

Daniel-Constantin Mierla miconda at gmail.com
Thu Mar 1 15:55:40 CET 2018


Module: kamailio
Branch: 5.1
Commit: cc92737d06359d1812ec7bed22e4c253ae7ba2e9
URL: https://github.com/kamailio/kamailio/commit/cc92737d06359d1812ec7bed22e4c253ae7ba2e9

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-03-01T15:52:06+01:00

db_mongodb: create projection field to set the list of returned column

(cherry picked from commit d50498cf483cd22ac4e62af5aaa86fc27654f640)

---

Modified: src/modules/db_mongodb/mongodb_dbase.c

---

Diff:  https://github.com/kamailio/kamailio/commit/cc92737d06359d1812ec7bed22e4c253ae7ba2e9.diff
Patch: https://github.com/kamailio/kamailio/commit/cc92737d06359d1812ec7bed22e4c253ae7ba2e9.patch

---

diff --git a/src/modules/db_mongodb/mongodb_dbase.c b/src/modules/db_mongodb/mongodb_dbase.c
index 57f11dc930..1e790b8b9d 100644
--- a/src/modules/db_mongodb/mongodb_dbase.c
+++ b/src/modules/db_mongodb/mongodb_dbase.c
@@ -825,6 +825,7 @@ int db_mongodb_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op
 	km_mongodb_con_t *mgcon;
 	mongoc_client_t *client;
 	bson_t *seldoc = NULL;
+	bson_t bcols;
 	char *cname;
 	char b1;
 	char *jstr;
@@ -904,14 +905,23 @@ int db_mongodb_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op
 			LM_ERR("cannot initialize columns bson document\n");
 			goto error;
 		}
+		if(!bson_append_document_begin (mgcon->colsdoc, "projection", 10,
+					&bcols)) {
+			LM_ERR("failed to start projection of fields\n");
+			goto error;
+		}
 		for(i = 0; i < _nc; i++) {
-			if(!bson_append_int32(mgcon->colsdoc, _c[i]->s, _c[i]->len, 1))
+			if(!bson_append_int32(&bcols, _c[i]->s, _c[i]->len, 1))
 			{
 				LM_ERR("failed to append int to columns bson %.*s = %d [%d]\n",
 						_c[i]->len, _c[i]->s, 1, i);
 				goto error;
 			}
 		}
+		if(!bson_append_document_end (mgcon->colsdoc, &bcols)) {
+			LM_ERR("failed to end projection of fields\n");
+			goto error;
+		}
 		if(is_printable(L_DBG)) {
 			jstr = bson_as_json (mgcon->colsdoc, NULL);
 			LM_DBG("columns filter: %s\n", jstr);




More information about the sr-dev mailing list