I'm working on a service method that can run mongodb aggregate queries from a json input. The idea is that you would use Builders to generate a query, convert that query to json, pass it to the service to be deserialized and run. For find queries I was able to use Bson documents like so
public string DoGenericFind(string queryDoc, string collectionName)
{
BsonDocument document = BsonSerializer.Deserialize<BsonDocument>(queryDoc);
var results = _context.Database.GetCollection<dynamic>(collectionName).FindSync<BsonDocument>(document);
if (results == null)
return null;
else
return results.ToList().ToJson();
}
I'm having trouble finding a similar way to do this with aggregate. The only examples I'm finding around try to do something similar to this where they pass some kind of BsonDocument[]. However, the intellisense for my version of the driver(2.5) say that I need to pass a pipelineDefinition which I can't find good examples of how to use.