ドキュメントを取得するために mongodb に接続する C プログラムで問題が発生しました...解決方法がわかりません。助けてください...
レコード構造:
{ "District" : "HK",
"Contact": [ {"name":"Person A","telephone":"1111-1111"} ,
{"name":"Person B", "telephone":"2222-2222} ]
}
これが私のコードです:
while( mongo_cursor_next( cursor ) == MONGO_OK ){
bson_iterator iterator[1];
//print district
if ( bson_find( iterator, mongo_cursor_bson( cursor ), "District" )) {
printf( "District: %s\n", bson_iterator_string( iterator ) );
//print array elements
if ( bson_find( iterator, mongo_cursor_bson( cursor ), "Contact" )) {
bson_iterator subit[1];
bson_iterator_subiterator(iterator, subit);
//get array list element one by one
while(bson_iterator_more(subit)){
if(bson_iterator_next(subit)!=BSON_EOO){
bson sub_Object[1];
bson_iterator_subobject_init(subit, sub_Object,1);
//bson_print(sub_Object);
//comment out the following bson_find could show the expected result
if(bson_find(subit, sub_Object, "name"))
printf("\tName : %s\n", bson_iterator_string(subit));
if(bson_find(subit, sub_Object, "telephone"))
printf("\tTelephone: %s\n", bson_iterator_string(subit));
bson_destroy(sub_Object);
}
}
}
}
出力
地区: 香港
名前: A
さん 電話: 1111-1111
パーソン B の記録が消えた理由を知っている人はいますか??
2番目のwhileループ内でbson_findを使用しないかどうかをテストしました.bson_printによってすべての要素を出力できます!!
mongodbにバグはありますか?? それとも私のコードが間違っていますか?
どうもありがとうございました!!!