我有一个MongoDB集合"foos",其中包含的每个项目都有一个"条"array.也就是说,"foo"具有以下模式:
{
"id": UUID
"name": string
...
"bars": [
"id": UUID
"key": string
...
]
}
我需要在name和bar上创建一个索引.使用MongoDB C#键.网络Mongo 司机.
我假设我可以使用Linq Select函数来完成以下操作:
Indexes.Add(Context.Collection<FooDocument>().Indexes.CreateOne(
Builders<FooDocument>.IndexKeys
.Descending(x => x.Bars.Select(y => y.Key))));
但是,这会导致无效操作异常:
System.InvalidOperationException: 'Unable to determine the serialization information for x => x.Bars.Select(y => y.Id).'
The Mongo documentation on MultiKey indexes展示了如何使用简单的点符号创建这样的索引,即.
db.foos.createIndex( { "name": 1, "bars.key": 1 } )
然而,the MongoDB driver documentation似乎表明,像我这样使用Linq函数是正确的.
How can I create a multikey index on my collection using the MongoDB .NET Driver, preferably using a Linq function?