【发布时间】:2017-08-08 21:49:17
【问题描述】:
有没有办法使用 C# 驱动程序创建强类型嵌套索引。
我想要这种索引:db.foos.ensureIndex({'Bars.Baz': 1});
public class Foo {
public Something() { }
public List<Bar> Bars { get;set; }
}
public class Bar {
public string Baz { get; set; }
}
var collection = database.GetCollection<Foo>("foos");
collection.Indexes.CreateOne(Builder<Foo>.IndexKeys.Ascending(/*What goes here?*/));
以下工作但创建“Bars.0.Baz”的索引:
collection.Indexes.CreateOne(Builders<Foo>.IndexKeys.Ascending(x => x.Bars[0].Baz));
这根本不起作用,并出现序列化错误
collection.Indexes.CreateOne(Builders<Foo>.IndexKeys.Ascending(x => x.Bars.Select(y => y.Baz)));
这可行,但添加了“Baz”的索引
collection.Indexes.CreateOne(Builders<Foo>.IndexKeys.Ascending(x => x.Bars.First().Baz));
他们都不想添加“Bars.Baz”的索引
MongoDB驱动版本是2.4.3.23
【问题讨论】:
标签: c# mongodb mongodb-.net-driver