ForerunnerDB icon indicating copy to clipboard operation
ForerunnerDB copied to clipboard

Advanced joins do not traverse arrays with $multi

Open wfdd opened this issue 9 years ago • 3 comments

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]

wfdd avatar Sep 20 '16 10:09 wfdd

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.

wfdd avatar Sep 20 '16 10:09 wfdd

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?

Irrelon avatar Sep 20 '16 10:09 Irrelon

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').

wfdd avatar Sep 20 '16 11:09 wfdd