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

$limit being applied against all items in context not each item in context #8

Open
ericuldall opened this issue Feb 17, 2024 · 2 comments

Comments

@ericuldall
Copy link

I have the following loader:

 products: virtual(async (item, context) => {
    return context.params.loader.service('saved-products').multi('lists').load(item._id, {
      ...getAuthenticatedParams(context),
      query: {
        userId: item.userId,
        $limit: 4,
        $sort: { createdAt: -1 },
        $select: ['_id', 'image', 'imageUpload', 'lists'],
      },
    });
  }),

So for this it's loading matching saved products in each of my lists. I want it to $limit to 4 saved products per list. But the actual behavior is it's limiting to 4 saved products total (across all lists). So any list after the first 4 products returned show as empty lists.

Am I doing something wrong or is this a bug?

@ericuldall ericuldall changed the title $limit be applied against all items in context not each item in context $limit being applied against all items in context not each item in context Feb 17, 2024
@DaddyWarbucks
Copy link
Collaborator

It's not a bug in the loader nor something you are doing wrong. It's more of a misunderstanding of how the loader works and some of its limitations. It's important to understand how the loader turns your queries into an $in query. I think I actually have some updated branches/code that disallows the $limit.
But I see what you are going for there. I suppose I could rig up something for $limit with multi, but it won't be a true DB query.
I am away from the office this week. Please ping me next week and we can work more on this

@ericuldall
Copy link
Author

Okay, that makes sense that in this case since i'm not directly targeting _id's the loader wouldn't be effective.

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