[SERVER-12685] Expand $unwind behavior to include empty documents optionally Created: 11/Feb/14 Updated: 05/Feb/16 Resolved: 21/Sep/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | 3.1.8 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Ramesh Reddy | Assignee: | Charlie Swanson |
| Resolution: | Done | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
Currently when a document has nested array based documents, $unwind only shows records where parent documents contain the $unwind field. It would be useful in certain scenarios to have an $unwind stage with some other optional configuration, which will produce an output document for a document that does not contain the $unwind field. In a collection with the following documents:
When you run this pipeline:
You get the following results:
It would be nice if it also returned the following result:
Here is user groups discussion on this topic There is workaround exists using the $IFNULL, see the above link. |
| Comments |
| Comment by Asya Kamsky [ 24/Sep/15 ] | ||||||||||||||||||
no, due to | ||||||||||||||||||
| Comment by NOVALUE Mitar [ 24/Sep/15 ] | ||||||||||||||||||
|
But if it is not an array, null, or not existing, then it still throws an error? OK. | ||||||||||||||||||
| Comment by Asya Kamsky [ 24/Sep/15 ] | ||||||||||||||||||
|
Not a problem: here is how it works in 3.1.8 dev release:
The above shows the old pre-3.2 behavior works exactly the same way. If you use the new option with value false, it's exactly equivalent to not using the option at all, so we should see same result:
If we change the value of the option to true we should get all the previously "dropped" documents from the unwind:
You can see the three extra documents, in each "a" is the same as it was before unwind. | ||||||||||||||||||
| Comment by NOVALUE Mitar [ 24/Sep/15 ] | ||||||||||||||||||
|
Sorry that it is hard to test runtime of the trunk code. I was basing my understanding on the documentation in the commit message. | ||||||||||||||||||
| Comment by Asya Kamsky [ 24/Sep/15 ] | ||||||||||||||||||
|
Using this option, every document goes through the pipeline - none are lost during $unwind. Please try it before assuming it doesn't do what you want. | ||||||||||||||||||
| Comment by NOVALUE Mitar [ 24/Sep/15 ] | ||||||||||||||||||
|
How does this address this ticket? This is not true. This addresses something, but not this ticket. This ticket was if the field does not exist, that document should be copied over. But you added feature for null and empty arrays? I think that for null I can maybe understand (it could be similar to when field does not exist), but if an array is empty, then no document should be constructed on the output, no? So, please add a feature where for nonexisting (or null) field document is copied over. And how it behaves for empty array should be some other option, if at all. (Not sure who asked for that feature?) So the discussion in the Google groups and also why I voted for this ticket was to support left outer join-like semantics. And unwinding an empty list is not how it works. Nonexisting value (or maybe null) is more reasonable. (I would claim that only non-existing value documents should be copied over and null value fields should throw an error. And empty list fields should produce no output documents.) | ||||||||||||||||||
| Comment by Charlie Swanson [ 21/Sep/15 ] | ||||||||||||||||||
|
This should be resolved as of 3cb6039e5d2968b1e361bf592452b95c7a76c770. |