0

Here's the structure part of my collection :

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

The use of :

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

is "working" but in reality simply returns me the result of the first field of the array found... How to recover precisely the value of the "id" or "target" field please ?

John S
  • 231
  • 3
  • 11

1 Answers1

1

You can also use bson_iterator_more and bson_iterator_next upon the sub-iterator(It was still an iterator).

try this:

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));
    }
  }
}
newkedison
  • 158
  • 1
  • 5