0

这是我收藏的结构部分:

{
    _id: {
        id:"6a6ca923517f304900badd98",
        target:"00badd6a6ca923517f304998e4df"
    },
...
}

指某东西的用途 :

if(bson_find(iterator, mongo_cursor_bson(cursor), "_id")){
   bson_iterator_subiterator(iterator, sub);
   id = (char*)bson_iterator_string(sub);
}

是“工作”,但实际上只是返回我找到的数组的第一个字段的结果......请问如何准确恢复“id”或“target”字段的值?

4

1 回答 1

1

您还可以在子迭代器上使用bson_iterator_moreand (它仍然是一个迭代器)。bson_iterator_next

尝试这个:

if(bson_find(iterator, mongo_cursor_bson(cursor), "_id"))
{
  bson_iterator_subiterator(iterator, sub);
  while(bson_iterator_more(sub))
  {
    if (bson_iterator_next(sub) != BSON_EOO)
    {
      printf("%s: %s\n", bson_iterator_key(sub), bson_iterator_string(sub));
    }
  }
}
于 2013-07-24T06:25:03.220 回答