0

当我的结构看起来像这样时:

X: {
   Y: "blabla"
}

所以我使用函数“bson_iter_find_descendant(&iter, " XY ", &desc)" 来恢复我的数据。但是当我的结构看起来像这样时,如何检索“ XY ”、“ XZ ”的值:

X: [
   {
      Y: "blihblih"
   },
   {
      Z: "bloublou"
   }
]

请注意,我使用的是最新版本的 MongoDB-C Driver ...

先感谢您!

4

1 回答 1

2

//MONGOC_VERSION_S "0.92.3" ./configure --with-libbson=bundled

const bson_t *doc;
bson_iter_t iter;
bson_iter_t iter2;
uint32_t length;

mongoc_client_get_collection mongoc_collection_find mongoc_cursor_next

接着

bson_iter_init(&iter,doc);
bson_iter_find_descendant(&iter,"X.0.Y",&iter2); // for first
bson_iter_find_descendant(&iter,"X.1.Z",&iter2); // for second array element

printf("%d\n",bson_iter_type(&iter2));

for type 2
printf("%s\n",bson_iter_utf8(&iter2,&length));
于 2014-03-21T04:51:59.357 回答