Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$lookup operator does not work #40

Open
ar124officialwd opened this issue Dec 27, 2021 · 3 comments
Open

$lookup operator does not work #40

ar124officialwd opened this issue Dec 27, 2021 · 3 comments

Comments

@ar124officialwd
Copy link

I'm unable to use $lookup operator in aggregatePaginate. The expected result property (products in query below) is always null and excluded from the results document at all. It's otherwise working fine without paginate (using aggregate method)

Following is the query, I'm running.

  query = [
    { $match: {} },

    {
      $lookup: {
        from: 'products',
        let: { attraction: '$_id' },
        // localField: '_id',
        // foreignField: 'attraction',
        as: 'products',
        pipeline: [
          {
            $match: {
              $expr: {
                $eq: ['$attraction', '$$attraction'],
              },
            },
          },

          { $project: { price: 1 } },

          { $sort: { 'price.price': 1 } },

          { $limit: 1 },
        ],
      },
    },
  ];
@mikelinden1
Copy link

I'm running into the same problem. Did you find a solution @ar124official2019 ?

@mikelinden1
Copy link

Actually, I figured it out. I was passing my pipeline stages to aggregatePaginate instead of an aggregate.

@ar124officialwd
Copy link
Author

ar124officialwd commented Feb 1, 2023

Actually, I figured it out. I was passing my pipeline stages to aggregatePaginate instead of an aggregate.

I don't exactly remember that problem, yet I clearly remember that I opted out of it and rather wrote my custom aggregate. I would definitely reproduce it and try your solution.

Edit: infact my problem was that I wanted to aggregate with paginate and that did never work for me, so I wrote custom logic.

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

No branches or pull requests

2 participants