Provide a type-safe way to create multikey indexes

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.0.1
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      As background, consider first the following classes:

      public class Product
      {
          public ObjectId Id;
          public Review Review;
      }
      
      public class Review
      {
          public string Author;
          // etc...
      }
      

      Given these classes, one can easily create an index on the Author of a Review in a type-safe manner:

      var builder = Builders<Product>.IndexKeys;
      var keys = builder.Ascending(x => x.Review.Author);
      

      However, suppose that instead of one Review, the Product class defined an enumerable of Reviews?

      public class Product
      {
          public ObjectId Id;
          public Review[] Reviews;
      }
      

      If you attempt to create an index on the Authors of the Reviews you get a compile time error:

      var builder = Builders<Product>.IndexKeys;
      var keys = builder.Ascending(x => x.Reviews.Author); // compile time error!
      

      We need some way to support creating multikey indexes in a type-safe way.

              Assignee:
              Unassigned
              Reporter:
              Robert Stam
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: