[CSHARP-3083] Linq Driver Performing pipeline instead of find on query Created: 29/Apr/20 Updated: 27/Oct/23 Resolved: 29/Apr/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.10.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Michael Fyffe | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Reporting this as a bug BUT i would have expected the linq query to generate the same qeury under the covers as the find query. Instead the linq query is generating an aggregation pipeline.
``` var document = GetCollection<MediaDocument>() .Find(x => x.ImageUniqueIdentifier == imageUniqueIdentifier) .FirstOrDefault(); ```
``` var document = GetCollection<MediaDocument>() .AsQueryable() .Where(x => x.ImageUniqueIdentifier == imageUniqueIdentifier) .FirstOrDefault(); ``` |
| Comments |
| Comment by Michael Fyffe [ 29/Apr/20 ] |
|
Hey DMitry, Are you sure there is no performance difference? Under the covers mongodb is taking a completely different path for execution ( find vs aggregation pipeline ). Do you happen to have documentation discussing this that i can take a peek at!
Thanks for the help!! |
| Comment by Dmitry Lukyanov (Inactive) [ 29/Apr/20 ] |
|
Hello michael_fyffe@homedepot.com, That is by design. All LINQ queries are translated to an aggregation pipeline. While it is true that some simple LINQ queries could in theory be translated to a Find query, many other LINQ queries need to be translated to an aggregation pipeline because they need features that are not available in a simple Find. There is no performance penalty for using an aggregation pipeline, so there is no need to make any attempt to translate simple LINQ queries to a Find query instead of an aggregation pipeline. Therefore, all LINQ queries are translated to an aggregation pipeline no matter how simple they might be. |