Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1309

IndexKeysDefinitionBuilder should support defining multikey indexes on members of an array of embedded documents

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: API
    • Labels:
      None

      Description

      Given the following classes:

      public class User
      {
          public Object Id { get; set; }
          public IEnumerable<Login> Logins { get; set; }
          // etc...
      }
       
      public class Login
      {
          public string LoginProvider { get; set; }
          public string ProviderKey { get; set; }
          // etc...
      }
      

      There should be a type-safe way to create multikey indexes on members of the embedded Login documents. One possible way to express that could be:

      var indexKeysDefinition = Builders<User>.IndexKeys
          .Ascending(user => user.Logins.Select(login => login.LoginProvider))
          .Ascending(user => user.Logins.Select(login => login.ProviderKey));

      Workaround

      Use strings instead.

      var indexKeysDefinition = Builders<User>.IndexKeys
          .Ascending("Logins.LoginProvider")
          .Ascending("Logins.ProviderKey");
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              craiggwilson Craig Wilson
              Participants:
              Votes:
              10 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated: