瀏覽代碼

db_mongodb: re-init iterator and search again if fails to find from crt position

Daniel-Constantin Mierla 8 年之前
父節點
當前提交
501c41dd35
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10 3
      src/modules/db_mongodb/mongodb_dbase.c

+ 10 - 3
src/modules/db_mongodb/mongodb_dbase.c

@@ -377,9 +377,16 @@ int db_mongodb_get_columns(const db1_con_t* _h, db1_res_t* _r)
 		LM_DBG("Found a field[%d] named: %s\n", col, colname);
 		if(mgres->colsdoc) {
 			if(!bson_iter_find(&riter, colname)) {
-				LM_ERR("field [%s] not found in result iterator\n",
-						colname);
-				return -4;
+				/* re-init the iterator */
+				if (!bson_iter_init (&riter, mgres->rdoc)) {
+					LM_ERR("failed to initialize result iterator\n");
+					return -3;
+				}
+				if(!bson_iter_find(&riter, colname)) {
+					LM_ERR("field [%s] not found in result iterator\n",
+							colname);
+					return -4;
+				}
 			}
 			coltype = bson_iter_type(&riter);
 		} else {