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

Does string field definition should match model filed name or document field name?

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON

      Hi.

      FilterDefinitionBuilder could accept string as first parameter for all of their method. Like this: 

      var filterDefinition = Builders<Employee>.Filter.Eq("fieldName", "someValue");

      Does this field should match property name of my model or it should match field name from document?

      My issue that filter definition renders inproper query for date field if provided field name string doesnt match my model property name exactly.

      In following example "dateOfBirth" doesn't mapped to model field Employee.DateOfBirth

      var filterDefinition = Builders<Employee>.Filter.Eq("dateOfBirth", "2019-01-16");
      mongoFilterDefinition.Render(coll.DocumentSerializer, coll.Settings.SerializerRegistry) // returns { "dateOfBirth" : "2019-01-16" }
      

      And this filter doesn't work.

      But if we will provide field name like "DateOfBirth" it will be mapped:

      var filterDefinition = Builders<Employee>.Filter.Eq("DateOfBirth", "2019-01-16");
      mongoFilterDefinition.Render(coll.DocumentSerializer, coll.Settings.SerializerRegistry) // returns { "dateOfBirth" : ISODate("2019-01-16T00:00:00Z") }
      

      I found a place where this behaviour could be changed but I'm not sure if it's a bug.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            veujin Mikhail Bolshakov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: