I cannot find a way to add a “Sort” to the MongoDB Search function within C#. Am I missing something or must this be done via BsonDocuments?
Simple Example:
coll.Aggregate(new AggregateOptions()
{
BatchSize = 1000
})
.Search(
compound.ToSearchDefinition(),
indexName: "myCoolIndex",
highlight: new SearchHighlightOptions<T>(Builders<T>.SearchPath.Multi(searchpaths)),
***** SEARCH GO HERE? *****
returnStoredSource: true)
Of course I know I can do the below, but is it part of the C# driver and I am just missing it?
new BsonArray
{
new BsonDocument("$search",
new BsonDocument
{
{ "index", "myCoolIndex" },
{ "compound",
new BsonDocument("should",
new BsonArray
{
new BsonDocument("autocomplete",
new BsonDocument
{
{ "query", "aSearchValue" },
{ "path", "somefieldpath" }
}),
new BsonDocument("autocomplete",
new BsonDocument
{
{ "query", "aSearchValue" },
{ "path", "a Different Field Path" }
})
}) },
{ "highlight",
new BsonDocument("path",
new BsonArray
{
"some Field Path",
"a Different Field Path"
}) },
{ "sort",
new BsonDocument("A Field to Sort On", -1) },
{ "returnStoredSource", true }
}),
new BsonDocument("$addFields",
new BsonDocument("SearchHighlightDetails",
new BsonDocument("$meta", "searchHighlights")))
}