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

Find methods account for "IgnoreIfDefault"

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.1
    • Component/s: Linq
    • Labels:
      None
    • Minor Change

      Simple scenario here:

      Trying to do a simple find on a field that is set to "IgnoreIfDefault", and thus is not a field in the document if the value is the default. However, this causes problems with querying...

      Collection.Find(d => d.ActiveState == ActiveStateType.Active).ToListAsync().Result
      

      With this class:

      public class JebsClass {
           [BsonIgnoreIfDefault]
           [BsonDefaultValue(ActiveStateType.Active)]
           public ActiveStateType ActiveState { get; set; }
           public int Field1 {get; set; }
      }
      

      This finds records like this

      {
           Field1: 5,
           ActiveState: "Active"
      }
      

      but NOT documents like this

      {
           Field1: 5
      }
      

      It seems to me that the Find interface methods should take into account Default values, and update the translated query to include a $exists: false for ActiveState.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jebber007 Jeb
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: