I have developed a simple API which allows you to build up an array of search criteria within a MongoDB Collection. I now need to be able to convert this array into an actual Mongo Query, and this part is where I am having extreme difficulty.
Ideally I am after some syntax that will allow me to do the following pseudo code:
var query = new QueryBuilder();
foreach (var group in groups)
{
switch (group.Condition)
{
case GroupCondition.Or:
query.Or(group.Queries);
break;
case GroupCondition.And:
query.And(group.Queries);
break;
}
}
return myCollection.FindAs(type, query);
I actually want to build up slightly more complex queries, but ultimately I am after the functionality to dynamically build up my queries with objects as seen in my pseudo code above.
Feel free to ask me for additional details if I have not made myself clear enough about what I am trying to achieve.