`graphLookup` alternative for large memory usage

I am using Mongo graphLookup to fetch the data from the collection.
When fetching some of the documents from large collection, I encounter the memory usage limit. I have read the forum here How to use aggregation for large collection? but I could not have the conclusion of the solution that use the graphLookup. If I manually recursive fetch the data, it will take too much time. Is there any alternative way to fetch the data from large collection without the restriction of limited memory unlike graphLookup do?

here is what my graphLookup look like:

.aggregate([
        {
          $match: {
            _id: new Types.ObjectId(parentId),
          },
        },
        {
          $graphLookup: {
            from: 'users',
            startWith: '$parentId',
            connectFromField: 'parentId',
            connectToField: '_id',
            as: 'parents',
            depthField: 'level',
            maxDepth: Math.max(0, levelLimit - 2), // less than 10
          },
        },
1 Like