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

Provide a type-safe way to create multikey indexes

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.0.1
    • API
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: