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

LINQ queries with coll.Any() can be improved to avoid $elemMatch.

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 2.1
    • 1.8.3
    • Linq
    • None
    • Fully Compatible

    Description

      Presently any query of the form:

      coll.Where(c => c.Array.Any(a => a.value == val))

      maps to the database as something like:

      db.Coll.find({ "Array" : { "$elemMatch" :

      {"Value" : val }

      } } )

      A faster query which is entirely acheivable in the C# driver is:

      db.Coll.find(

      { "Array.Value" : val }

      )

      For example, this query:

      books.Where(b => b.Ratings.Any(r => r.Value >= 0))

      becomes:

      db.Book.find({ "Ratings" : { "$elemMatch" : {"Value" :

      { "$gte" : 0 }

      } } } )

      It should be

      db.Book.find({ "Ratings.Value":

      { "$gte" : 0 }

      } )

      Attachments

        Activity

          People

            craig.wilson@mongodb.com Craig Wilson
            mkennedy66996693 Michael Kennedy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: