mixmaxhq / mongo-cursor-pagination

Cursor-based pagination for Mongo
https://www.mixmax.com/careers
MIT License
229 stars 72 forks source link

Allow user to restrict fields to return when using mongoose #236

Open OlivierAlbertini opened 4 years ago

OlivierAlbertini commented 4 years ago

By default, queries in MongoDB return all fields in matching documents. To limit the amount of data that MongoDB sends to applications, you can include a projection document to specify or restrict fields to return.

Issue

using params.fields does nothing and all fields is returned in matching documents.

Expected

 it('returns data with expected fields', async () => {
    const data = await Post.paginate({ fields: { title: 1 }, limit: 1 });
    const [post] = data.results;
    expect(post.title).toBeTruthy();
    expect(post.date).toBeFalsy();
    expect(post.author).toBeFalsy();
    expect(post.body).toBeFalsy();
  });

The following test failed.

This PR seems to solve the issue : https://github.com/mixmaxhq/mongo-cursor-pagination/pull/60

Please make a review if possible

mark-bt commented 4 years ago

I am having this issue as well. Did you ever find a solution?

OlivierAlbertini commented 4 years ago

I am having this issue as well. Did you ever find a solution?

Yes, this PR resolves the issue https://github.com/mixmaxhq/mongo-cursor-pagination/pull/239

don't hesitate to review the PR.