2017-07-21 3 views
0

mongoの結果を以下のようにfield-by-fieldより速くデータ構造に解析する方法はありますか?私は現在これをやっているし、それは非常に遅いです。mongo結果のデータをフィールド単位で取得するより高速な方法ですか?

mongocxx::cursor cursor = m_coll.find(<some-query>); 
for (bsoncxx::document::view doc : cursor) 
{ 
    RecreatedObj readback; 
    readback.Area = doc["Area"].get_int32(); 
    readback.fieldOne = doc["fieldOne"].get_double(); 
    readback.fieldTwo = doc["fieldTwo"].get_double(); 
    readback.fieldThree = doc["fieldThree"].get_int32(); 
    ... 
} 

答えて

1

フィールドルックアップはO(N)なので、あなたは無意識にO(N^2)アルゴリズムを書いています。

より速い方法は、ドキュメントビューのフィールドを反復して、フィールド名のスイッチ/ケースで割り当てを行うことです。

関連する問題