Following is the code trying to use mongo query with project find option.
using bsoncxx::builder::stream::document;
mongocxx::options::find opts;
document condition, options;
const static int readdomain = 90000;
condition << "lastRead" << open_document << "$gte" << readdomain << close_document;
options << "read" << 1;
opts.projection(options.view());
mongocxx::cursor cursor = collection.find(condition.view(), opts);
The above query without "opts" can work well while the one with "opts" will raise the following error.
terminate called after throwing an instance of 'bsoncxx::v_noabi::exception'
what(): unset document::element
[zy1989:20594] *** Process received signal ***
[zy1989:20594] Signal: Aborted (6)
[zy1989:20594] Signal code: (-6)
[zy1989:20594] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10d10)[0x7f05d3b65d10]
[zy1989:20594] [ 1] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f05d37c0267]
[zy1989:20594] [ 2] /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f05d37c1eca]
[zy1989:20594] [ 3] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x16d)[0x7f05d471106d]
[zy1989:20594] [ 4] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x5eee6)[0x7f05d470eee6]
[zy1989:20594] [ 5] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x5ef31)[0x7f05d470ef31]
[zy1989:20594] [ 6] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x5f149)[0x7f05d470f149]
[zy1989:20594] [ 7] /usr/local/lib/libbsoncxx.so._noabi(_ZNK7bsoncxx7v_noabi8document7element4typeEv+0xdd)[0x7f05d49cfe0d]
[zy1989:20594] [ 8] /usr/local/lib/libbsoncxx.so._noabi(_ZN7bsoncxx7v_noabi7to_jsonENS0_8document7elementE+0x286)[0x7f05d49d8926]
[zy1989:20594] [ 9] ./ArticleIndexComputation(_Z7groupbyN8mongocxx7v_noabi6cursor8iteratorElRSt6vectorIN7bsoncxx7v_noabi8document4viewESaIS7_EERSt3mapIiS3_IiSaIiEESt4lessIiESaISt4pairIKiSD_EEE+0x186)[0x415826]
[zy1989:20594] [10] ./ArticleIndexComputation(main+0x1181)[0x417161]
[zy1989:20594] [11] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f05d37aba40]
[zy1989:20594] [12] ./ArticleIndexComputation(_start+0x29)[0x415439]
[zy1989:20594] *** End of error message ***