When using includes (nested queries) we can use toArray to materialize the results of the nested query into an array instead of a collection. However, when the nested query uses findOne to return a single element it is annoying to have to deal with a singleton array. We want a toArray equivalent for this use case that simply returns that one element.
I'm questioning if "toArray" is a good name because it means we now have to introduce another function for subqueries that return a single element. But conceptually both are doing the same: materializing the underlying collection. So perhaps materialize(subquery) would be a better name and it will return an array if the underlying query returns multiple results and a single element if it's a singular query.
When using includes (nested queries) we can use
toArrayto materialize the results of the nested query into an array instead of a collection. However, when the nested query usesfindOneto return a single element it is annoying to have to deal with a singleton array. We want atoArrayequivalent for this use case that simply returns that one element.I'm questioning if "toArray" is a good name because it means we now have to introduce another function for subqueries that return a single element. But conceptually both are doing the same: materializing the underlying collection. So perhaps
materialize(subquery)would be a better name and it will return an array if the underlying query returns multiple results and a single element if it's a singular query.