[CSHARP-1359] Runtime exception using Project with Aggregate Created: 07/Aug/15 Updated: 09/Aug/15 Resolved: 08/Aug/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 2.0.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Robert Stam | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Given the following classes:
And the following sample data in a collection:
The following code compiles correctly but throws an exception at runtime:
The stack trace is:
|
| Comments |
| Comment by Robert Stam [ 09/Aug/15 ] | |||
|
Regarding the documentation, it was unclear that "new type" actually meant "instantiating a new instance of a type using the new keyword". We should reopen this ticket (or create new ones) to: 1. Clarify the documentation of Project to document exactly what is and isn't supported | |||
| Comment by Craig Wilson [ 08/Aug/15 ] | |||
|
"a new type, either anonymous or named, must be used." That seems clear to me. The problem is we don't have access to the entire tree, which means we cannot project a fake field into the next stage. This is different in LINQ, where we do have access to the entire tree and can project a fake a field. Regardless, as it is now, doing what you want is not possible. There is a chance we can change this in 2.1, but, because this is documented, it is not a bug. | |||
| Comment by Robert Stam [ 08/Aug/15 ] | |||
|
There may be more going on here than you think. It gave me the impression of working, because it rendered the pipeline as:
But the resulting documents were:
instead of:
which is what the deserializer expected. The documentation you linked to only describes using anonymous types to describe the projection. It is unclear what should happen if the projection is to a regular class. Certainly the compile time result of this aggregate method is claiming that the result is a List<X>. | |||
| Comment by Craig Wilson [ 08/Aug/15 ] | |||
|
This is documented here: http://mongodb.github.io/mongo-csharp-driver/2.0/reference/driver/crud/reading/#project. We could probably throw a better exception. |