这是我的收藏的结构部分:
{
...
likes: ['6a6ca923517f304900badd98','6a6ca923517f304900badd99','...'],
...
}
您可以建议我使用C lib检索“赞”字段中的值列表吗?
答案 0 :(得分:2)
我没有工作的MongoDB C驱动程序,但这应该有助于您入门。此外,文档应该帮助您(here)。
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 );
}
}
}