I want to create a compound index where one key should be in ascending, the second key in descending order.
How can I do this?
I have a string containing the property names the user selected.
collection.EnsureIndex(IndexKeys.Descending(selectedProperties[0]),
IndexKeys.Ascending(selectedProperties[1])),
IndexOptions.......
does not work
Here's one way:
var keys = new IndexKeysBuilder();
keys.Ascending(keyName1);
keys.Descending(keyName2);
var options = new IndexOptionsBuilder();
options.SetSparse(true);
options.SetUnique(false);
collection.EnsureIndex(keys, options);