[CSHARP-922] LINQ queries with coll.Any() can be improved to avoid $elemMatch. Created: 05/Mar/14 Updated: 20/Jan/16 Resolved: 08/May/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 1.8.3 |
| Fix Version/s: | 2.1 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Michael Kennedy | Assignee: | Craig Wilson |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Epic Link: | Rewrite Linq |
| Backwards Compatibility: | 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 }} ) |
| Comments |
| Comment by Githook User [ 08/May/15 ] |
|
Author: {u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}Message: |
| Comment by Michael Kennedy [ 05/Mar/14 ] |
|
Sorry I forgot to add this when I submitted: I tested this both on 2.4.9 and 2.6.0_rc0. |