-
Type: Improvement
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query
-
Fully Compatible
Think below $lookup aggregate:
use test db.test.insert([{id:1, x:10}, {id:2, y:11}]) db.test.insert({id:3, a:[{id:1}, {id:2}, {id:1}]}) db.test.aggregate([ {$match:{id:3}}, {$lookup: {from:'test', localField:'a.id', foreignField:'id', as:'xyz'}}, {$project:{xyz:1}} ])
The result have merged result with array length=2, but the source array a has length=3
{"xyz" : [ { "id" : 1, "x" : 10}, { "id" : 2, "y" : 11} ] }
The above result can cause issue in client application since if the id is same, the result will merged, different length from source, but if all the source id is unique, they have identical length.
The problem here is, it's related to input data, the application cannot predict whether the result is merged, and the 1-1 relation from source array to result array is broken!
Maybe can add an option to $lookup stage object say "unique: false" ? And not merge the result automatically.
- related to
-
SERVER-22881 lookup between local (multiple)array of values and foreign (single) value
- Closed