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

Make Query aggerators accept nulls

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      I propose to allow Query.And() (and, probably, Query.Or()) to accept nulls, silently ignoring them (threating them as "match all").
      Consider the following (pseudo)code:
      bool condition = ...;
      int data = ...;
      int? data2= ...;
      int? data3=...;
      var query = condition ? Query.Null : Query.EQ("Value", data);
      if (data2 != null)
      query = Query.And(query, Query.Eq("Value2", (int)data2);
      if (data2 != null)
      query = Query.And(query, Query.Eq("Value2", (int)data3);

      If nulls are allowed as arguments to Query.And, one can efficiently combine queries to create progressively more detailed requests. Currently, we have to resort to ugly things like Query.And() instead of Query.Null.
      If silently ignoring nulls is not an option (though I think it's fine from a design standpoint), a Query.Any property containing an empty query would be most welcome.

      P.S. I marked the issue as non-backward-breaking since I don't think that anyone relied on exception being thrown when null is passed into Query.And() or Query.Or().

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            onyxmaster Aristarkh Zagorodnikov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: