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

As of v2.23.0, Expressions accessing Dictionary.Keys are no longer supported via IndexKeysDefinitionBuilder

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Index Management
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      We are trying to update to the latest Mongo C# Driver to use the new EntityFramework lib, but haven’t been able to get past a breaking change that was bug (or perhaps a bug that was introduce) in v2.23.0. In v2.22.0 and prior, we have been able to pass Dictionary.Keys in an Expression via IndexKeysDefinitionBuilder. For example:

      public class Thing
      {
        [BsonRepresentation(BsonType.ObjectId)]
        [BsonIgnoreIfDefault]
        public string Id { get; set; }
        public string Name { get; set; }
        public Dictionary<string,string> Attributes { get; set; }
      }
      
      // Given the following
      
      protected static IndexKeysDefinitionBuilder<TEntity> Index => Builders<TEntity>.IndexKeys;
      
      // Some data layer code that builds indexes
      
      var collection = database.GetCollection<Thing>("things");
      
      await collection.Indexes.CreateOneAsync(
        new CreateIndexModel<Thing>(
          Index.Combine(
            Index.Ascending(o => o.Name),
            Index.Ascending(o => o.Attributes.Keys))));
      

      Is there a different way to build this Expression now or was this a bug that got introduced? Any guidance is appreciated.

            Assignee:
            adelin.mbidaowona@mongodb.com Adelin Mbida Owona
            Reporter:
            crtaylor@verisk.com Clayton Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: