在 Cosmos 中将复合索引添加到 MongoDB API

Add compound Index to MongoDB API in Cosmos

我在我的应用程序中使用排序并使用 cosmos mongodb api 作为数据库。我在代码中创建了通配符索引以适应排序,但由于缺少复合索引,我仍然以某种方式收到错误。这是我创建索引的方式。

 var wcIndex = new IndexKeysDefinitionBuilder<T>().Wildcard();
 var wcIndexModel = new CreateIndexModel<T>(wcIndex, options);
 _collection = _database.GetCollection<T>(_collectionName);
 _collection.Indexes.CreateOneAsync(wcIndexModel);

我得到的错误是

The index path corresponding to the specified order-by item is excluded / The order by query does not have a corresponding composite index that it can be served from.

我是否可以为模型添加复合索引来完成排序?

我添加了以下代码,使其可以在 mongo Cosmos API.

中使用排序
 IndexKeysDefinition<T> keys =  "{'$**': 1}";
 var wildcardIndex = new CreateIndexModel<T>(keys);
_collection = _database.GetCollection<T>(_collectionName);
_collection.Indexes.CreateOne(wildcardIndex);