Unless I'm missing something, there appear to be large gaps in the documentation for the C# MongoDb driver.
I'm trying to take an IMongoQueryable (which is the result of various LINQ Where, Select, etc. operations) and store the results in a collection, on the database side. Of course, I could iterate through it on the client side and persist it that way, but even in batches that's not efficient, and in shell it's quite an easy operation to use $merge or $out.
On a collection, there's the method AggregateToCollection<TResult>() which is exactly what I want I believe, but it takes a PiplineDefinition<TDocument, TResult> parameter that I have little idea how to actually generate from the IMongoQueryable.
I've been going down the rabbit hole of using GetExecutionModel() on the IMongoQueryable to get a BsonDocument or Json string, but then I still have no clue how to turn that into the PipelineDefinition that I need!
What I would have thought I would find, would be an extension method on IMongoQueryable that would allow me to send it to be merged into a collection.
So far to be able to send an IMongoQueryable to a collection, I have something along the lines of:
var executionModelDocument = queryable.GetExecutionModel().ToBsonDocument();
// somehow turn the document into pipeline stages and a pipeline??
await _database.GetCollection<TDocument>().AggregateToCollectionAsync<TResult>(pipeline);
How do I actually make this happen?