Skip to content

Conversation

@cray0000
Copy link
Contributor

What

$lookup was not working in $aggregate. It's like a JOIN in SQL. Very useful in complex aggregation queries.

How

Mingo has to be able to search in a collection we are doing the $lookup on. By default it doesn't know how to access that collection's documents.

To make it know we need to provide the collectionResolver option into the Mingo.Aggregator() with the logic to source the documents for the lookup over a particular collection.

Also the subscriptions to $aggregate queries were not working correctly since it's a special case which requires doing a full query on each doc change. So added it to canPollDoc to be ignored.

Tests

Added an extra test for $lookup

Concerns

I'm not sure whether it's required to do db._getSnapshotSync() for each document before casting it into the Mongo doc format, but ShareDBMingo.prototype.query() does it so I did it too.

The tests pass even if I just directly take db.docs[collection] and just do castToMongoDoc on them. So dunno, I'm probably missing some context here to understand why it passes with or without doing db._getSnapshotSync().

Copy link
Contributor

@ericyhwang ericyhwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Sorry, my email notifications have gotten a bit wonky, and I didn't see this come in earlier.

@ericyhwang ericyhwang merged commit 96f9f6a into share:master Jun 10, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants