I want to create and run a query using MongoDB C++ api having these conditions :
- timestamp is within a range AND
- From an array of strings, atleast one of them to be equal to the type
I have these fields in my MongoDB document: id_, timestamp, type
I have used builder stream to create my query. For the first condition to filter timestamp I did :
Document doc_timestamp;
doc_timestamp << "timestamp" << open_document <<
"$gt" << startTS <<
"$lte" << endTS
<< close_document
If I run the first condition alone, it runs perfectly. But I am not sure how to do it for type field. I did like this:
Document doc_type;
auto arr_type = doc_type <<
"$or" << open_array;
for (auto nNum : nTypes) {
arr_type = arr_type << "type" << std::to_string(nNum);
}
arr_type << close_array;
This filter does not work. It throws a run time error. What is wrong I am doing here? Also, how do I concatenate these two filter and pass it the find function to run the query.
Thanks in advance!