这是我收藏的结构部分:
{
...
likes: ['6a6ca923517f304900badd98','6a6ca923517f304900badd99','...'],
...
}
你能建议我用 C lib 检索“likes”字段中的值列表吗?
我没有可用的 MongoDB C 驱动程序,但这应该可以帮助您入门。此外,文档应该可以帮助您(此处)。
bson_iterator i[1], sub[i];
bson_type type;
const char * key;
const char * value;
// do query, get cursor
while(mongo_cursor_next(cursor) == MONGO_OK) {
// look for the "likes" field
if( bson_find( iterator, bson, "likes" )) {
// need to iterate through the elements of the array
bson_iterator_subiterator( iterator, sub );
// then iterate using "sub", until returns a BSON_EOO
while (BSON_EOO != bson_iterator_next( sub )) {
key = bson_iterator_key( sub );
// if it's a string...
value = bson_iterator_string( sub );
}
}
}