Frage

When my structure looks like this:

X: {
   Y: "blabla"
}

So I use the function "bson_iter_find_descendant(&iter, "X.Y", &desc)" to recover my data. But how to retrieve the values of "X.Y", "X.Z"... when my structure looks like this:

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

Note that I use the latest version of MongoDB-C Driver ...

Thank you in advance!

War es hilfreich?

Lösung

//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

and then

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));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top