Find methods account for "IgnoreIfDefault"

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.1
    • Component/s: LINQ
    • None
    • None
    • 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?
    • None
    • None
    • None
    • None
    • None
    • None

      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:
            James Kovacs
            Reporter:
            Jeb
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: