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

LINQ3 using list.Any(s => m.Field.Contains(s)) fails when Field is null/missing

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.21.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • 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

      Given a model like this:

      public Model {
         public List<string> Foo {get; set;}
      }

      Where the value is null or missing in mongodb.  And a LINQ query like this:

      var lookingFor = new List<string> { "value1", "value2" };
      var rows = collection.Where(model => lookingFor.Any(value => model.Foo.Contains(value))).ToList();

      The query will fail with MongoCommandException: "Command aggregate failed: $in requires an array as a second argument, found: missing."

      Rewriting the LINQ query slightly:

      var rows = collection.Where(model => model.Foo.Any(value => lookingFor.Contains(value))).ToList() 

      And the query succeeds.  This query worked in LINQ2.

       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Driver 2.20 using LINQ3

      How to Reproduce

      See above.

      Additional Background

      Discovered when LINQ3 is now the default LinqProvider.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            jgonyo@snagajob.com John Gonyo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: