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

not working with mongoDb cluster 7 #60

Open
Bamorem opened this issue Jul 3, 2024 · 5 comments
Open

not working with mongoDb cluster 7 #60

Bamorem opened this issue Jul 3, 2024 · 5 comments
Labels
fixed This issue is solved/fixed.

Comments

@Bamorem
Copy link

Bamorem commented Jul 3, 2024

After upgrating my cluster 6 to 7

my aggregatePaginate() doesn't woke using $geoNear.

It was working under a cluster 6, but not 7.

And the same aggregate is working with a simple aggregate() without paginate using geoNear.

@saminndex
Copy link

Same here $geoNear is not allowed to be used within a $facet stage

@saminndex
Copy link

I've fixed this @Bamorem - the documentation has this:

[useFacet] {Bool} - To use facet operator instead of using two queries. This is the new default. (Default: true)

So if you just change this to false it will resolve the issue

@aravindnc aravindnc added the fixed This issue is solved/fixed. label Jul 4, 2024
@erksdee
Copy link

erksdee commented Jul 16, 2024

I have also set the useFacet option to false, but it seems like the pagination is not working correctly. The nextPage is returning false, which is incorrect since I know there is more data. If I set it back to true, the pagination works correctly, but I get the error $_internalSearchMongotRemote is not allowed to be used within a $facet stage when I add the $search.

Can someone please advise? I'm not sure what I'm doing wrong.

Here is my pipeline:

const pipeline = [
  {
    $search: {
      index: 'title',
      text: {
        query: 'xxxxxxx',
        path: {
          wildcard: '*',
        },
      },
    },
  },
  {
    $match: {
      status: 'active',
      tags: {
        $in: ['tag1', 'tag2'],
      },
    },
  },
];

FYI, the above pipeline works with "mongoose-aggregate-paginate-v2": "1.0.7". But not with "mongoose-aggregate-paginate-v2": "1.1.1".

@MattLicense
Copy link
Contributor

@erksdee I found the solution to this to be passing in your aggregate as the countQuery in the paginationOptions. While debugging the issue I noticed once we set useFacet: false because we were also using $search in our pipeline.

So where before we had this:

      const aggregation = this.aggregateModel.aggregate(
        stages,
        { session: session },
      );

      return await this.aggregateModel.aggregatePaginate(aggregation, paginationOptions);

where paginationOptions contained useFacet: false, we now have this:

      const aggregation = this.aggregateModel.aggregate(
        stages,
        { session: session },
      );

      return await this.aggregateModel.aggregatePaginate(
        aggregation,
        {
          ...paginationOptions,
          countQuery: aggregation,
        },
      );

The issue appears to be here. constructPipeline correctly creates the query to count the total results, but it's not used when useFacet is false. If no countQuery is provided then the variable pipeline is used which is the limited query used to get a page of results, rather than the full results.

@aravindnc
Copy link
Owner

@MattLicense Would be nice if you can do a PR.

MattLicense added a commit to MattLicense/mongoose-aggregate-paginate-v2 that referenced this issue Jul 17, 2024
…r of documents.

Fixes issues where `useFacet` cannot be true (e.g. use of `$search` in a pipeline) returning only a single page of results as seen aravindnc#60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed This issue is solved/fixed.
Projects
None yet
Development

No branches or pull requests

5 participants