Advanced joins do not traverse arrays with $multi
Where
var advancedResult = coll2.find({}, {
"$join": [{
"coll1": {
"$where": {
"$query": {
"_id": "$$.my.friends.friendId"
}
},
"$as": "friendData",
"$require": false,
"$multi": true
}
}]
});
should? be equivalent to https://github.com/Irrelon/ForerunnerDB/blob/e48331ff29313109e3823c42695d06829e8be1ec/js/unitTests/tests/testsCollection.js#L1215-L1224, the former only matches the first friendId in my.friends:
> result.map(r => r.friendData.length)
[2, 2, 1]
> advancedResult.map(r => r.friendData.length)
[1, 1, 1]
Actually, $multi is a false flag here as it only applies to the foreign collection and it does seem to work since the result is an array.
Actually, $multi is a false flag here as it only applies to the foreign collection and it does seem to work since the result is an array.
Does that mean it is working as you expect?
No, because it still only pairs the first my.friends.friendId per friend list in coll2, i.e. the query selector in advancedResult is (in MongoDB syntax) actually interpreted as my.friends.0.friendId (note the '0').