mongo-cursor-pagination icon indicating copy to clipboard operation
mongo-cursor-pagination copied to clipboard

Allow user to restrict fields to return when using mongoose

Open OlivierAlbertini opened this issue 4 years ago • 2 comments

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

OlivierAlbertini avatar Sep 18 '20 22:09 OlivierAlbertini

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

mark-bt avatar Sep 25 '20 15:09 mark-bt

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.

OlivierAlbertini avatar Sep 25 '20 18:09 OlivierAlbertini