Get used where/sort condition from IMongoQueryable<TDocument>

Hello everyone!
Note: I have been playing with MongoDB C# driver for quite some time but still cannot consider myself an expert.

I am trying to figure out how to programmatically extract the fields used when using linq query in the MongoDB C# drivers.

For example, I have a code working code

collection.AsQueryable().Where(c => c.Region == “AU” && c.Rank > 0 && c.Rank < 100).ToListAsync();

Is there anyway to extract from the resulting IMongoQueryable (or any other possible type casting) the fields used in the conditon? (For the given example, the result should be “Region” & “Rank”)

I cannot change the structure of the LINQ so far, nor can I change it to use Builder.Filter

Hoping for a positive response or even just a nudge in the right direction.


On the return value from the above, the Expression object should have the query parameters, it seems to be split into left and right which can be recursively parsed to pull out all fields used in the query along with types etc.