|
As far as I know there is no way to force a natural sort (ascending or descending) in the middle of an aggregation pipeline, which in turn means there would be no way to translate a custom LINQ expression that attempted to specify a natural sort in the middle of a LINQ expression.
The closest thing I can think of is that you could specify an index hint that would affect the input to the pipeline. This hint is not part of the pipeline, but is an index hint to the aggregation command.
You could do this in C# like this:
var collection = CreateCollection();
|
var options = new AggregateOptions { Hint = new BsonDocument("$natural", -1) };
|
|
var queryable =
|
collection.AsQueryable(options)
|
.Take(1);
|
Which would result in the following command being sent to the server:
{ "aggregate" : "C", "pipeline" : [{ "$limit" : NumberLong(1) }], "hint" : { "$natural" : -1 }, "cursor" : { } }
|
|