C# MongoDB Indexes.CreateOneAsync异常使用Azure DocumentDB

C# MongoDB Indexes.CreateOneAsync异常使用Azure DocumentDB,c#,mongodb,azure,azure-cosmosdb,mongodb-indexes,C#,Mongodb,Azure,Azure Cosmosdb,Mongodb Indexes,我正在尝试使用连接到Azure DocumentDB实例的c#MongoDB驱动程序创建多个唯一索引,但在尝试创建第二个唯一索引时收到以下异常: MongoDB.Driver.MongoCommandException:'命令createIndexes失败:消息:{“错误”:[“唯一键的数目不能大于1。”]} 我似乎找不到任何关于Azure DocumentDB集合的唯一密钥数的文档。请注意,使用实际MongoDB实例时不会发生此异常 var keys = Builders<Product

我正在尝试使用连接到Azure DocumentDB实例的c#MongoDB驱动程序创建多个唯一索引,但在尝试创建第二个唯一索引时收到以下异常:

MongoDB.Driver.MongoCommandException:'命令createIndexes失败:消息:{“错误”:[“唯一键的数目不能大于1。”]}

我似乎找不到任何关于Azure DocumentDB集合的唯一密钥数的文档。请注意,使用实际MongoDB实例时不会发生此异常

var keys = Builders<ProductEntity>.IndexKeys.Ascending(p => p.UPC);
var options = new CreateIndexOptions<ProductEntity>() { Name = "UX_UPC", Unique = true, Sparse = true };
var result = await _collection.Indexes.CreateOneAsync(keys, options);

keys = Builders<ProductEntity>.IndexKeys.Ascending(p => p.Manufacturer).Ascending(p => p.MPN);
options = new CreateIndexOptions<ProductEntity>() { Name = "UX_Manufacturer_MPN", Unique = true, Sparse = true };
result = await _collection.Indexes.CreateOneAsync(keys, options);

public class ProductEntity
{
    public Guid Id { get; set; }
    public string UPC { get; set; }
    public string MPN { get; set; }
    public string Manufacturer { get; set; }
}
var-keys=Builders.IndexKeys.Ascending(p=>p.UPC);
var options=new CreateIndexOptions(){Name=“UX_UPC”,Unique=true,Sparse=true};
var result=await\u collection.index.CreateOneAsync(键、选项);
keys=Builders.IndexKeys.Ascending(p=>p.Manufacturer)、Ascending(p=>p.MPN);
options=newcreateIndexOptions(){Name=“UX\u制造商\u MPN”,Unique=true,Sparse=true};
结果=wait _collection.index.CreateOneAsync(键、选项);
公共类ProductEntity
{
公共Guid Id{get;set;}
公共字符串UPC{get;set;}
公共字符串MPN{get;set;}
公共字符串制造商{get;set;}
}
从中,我们可以发现它目前不支持唯一索引

通用性只是我们在Storage for DocumentDB:API for MongoDB中所有功能和改进的开始。在不久的将来,我们将发布对独特索引的支持,并进行几项重大性能改进

讨论的这个线程,您可以参考它。

从中,我们可以发现它目前不支持唯一索引

通用性只是我们在Storage for DocumentDB:API for MongoDB中所有功能和改进的开始。在不久的将来,我们将发布对独特索引的支持,并进行几项重大性能改进


此线程已讨论,您可以参考。

请共享类的定义
ProductEntity
,我们将根据您的代码复制此问题。您好,Fred,我已根据您的要求添加了类定义。请让我知道,如果你需要更多的信息来重现这个问题。谢谢请分享类的定义
ProductEntity
,我们将根据您的代码重现该问题。嗨,弗雷德,我按照您的要求添加了类定义。请让我知道,如果你需要更多的信息来重现这个问题。谢谢