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

Provide a type-safe way to create multikey indexes

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.0.1
    • Component/s: API
    • Labels:
      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 Unassigned
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: