Skip to content

Commit

Permalink
db_mongodb: create projection field to set the list of returned column
Browse files Browse the repository at this point in the history
(cherry picked from commit d50498c)
(cherry picked from commit cc92737)
  • Loading branch information
miconda committed Apr 25, 2018
1 parent 7b75831 commit 47e008c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/modules/db_mongodb/mongodb_dbase.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 47e008c

Please sign in to comment.