-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.4.4
-
Component/s: Aggregation Framework
-
Labels:None
-
ALL
I have 2 collections:
- Foo (_id, bars[])
- Bar (_id)
`bars` is the array of `Bar`'s ObjectId.
I would like to use `lookup` to get the array of `Bar` in EXACTLY order that the Id stored in `bars`.
{ $lookup: { from: 'bars', localField: 'bars, foreignField: '_id', as: 'bars' } }
Everything are ok, UNTIL I $push another Bar's ObjectId to BEGIN of the `bars` array. The $lookup will returns the array which the new one is in the end of array, NOT begin of array as my expectation.
For example:
{ _id: ..., bars: [A_id, B_id] }
=> A, B
But, after $push C_id to BEGIN of array:
{ _id: ..., bars: [C_id, A_id, B_id] }
=> A, B, C
And so on for D_id => A, B, C, D
My expectation is: A, B, C, D.