-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.4.3
-
Component/s: API
-
Environment:Net452
-
Not Needed
-
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; using System.Collections.Generic; using System.Linq; using Xunit; namespace IndexTest { [BsonIgnoreExtraElements] public class Foo { public Foo() { } public List<Bar> Bars { get; set; } } [BsonIgnoreExtraElements] public class Bar { public Bar() { } public string Baz { get; set; } } public class TestClass { [Fact] public void Test() { var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("test"); var collection = database.GetCollection<Foo>("foos"); // Invalid // { "Baz" : 1 } collection.Indexes.CreateOne(Builders<Foo>.IndexKeys.Ascending(x => x.Bars.First().Baz)); //Invalid // { "Bar.0.Baz" : 1 } collection.Indexes.CreateOne(Builders<Foo>.IndexKeys.Ascending(x => x.Bars[0].Baz)); // Valid but relies on magic string // { "Bar.Baz" : 1 } collection.Indexes.CreateOne("{\"Bar.Baz\" : 1}"); // Failure // System.InvalidOperationException : Unable to determine the serialization information for x => x.Bars.Select(y => y.Baz). collection.Indexes.CreateOne(Builders<Foo>.IndexKeys.Ascending(x => x.Bars.Select(y => y.Baz))); } } }
- is depended on by
-
CSHARP-1309 IndexKeysDefinitionBuilder should support defining multikey indexes on members of an array of embedded documents
- Closed