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

feat: support for leanWithVirtuals option to work with mongoose-lean-virtuals plugin #225

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

nexus-aissam
Copy link
Contributor

Description

Added support for leanWithVirtuals option to work seamlessly with the mongoose-lean-virtuals plugin. This enhancement allows virtual properties to be included in lean queries when using pagination.

Changes Made

  • Added leanWithVirtuals option to the pagination options
  • When leanWithVirtuals: true, the plugin will apply lean virtuals to the query
  • Maintained backward compatibility with existing lean options
  • Works in conjunction with mongoose-lean-virtuals plugin

Use Case Example

const options = {
  lean: true,
  leanWithVirtuals: true
};
Model.paginate({}, options);

@aravindnc
Copy link
Owner

@nexus-aissam Thanks. Can you please add some test cases too.

@nexus-aissam
Copy link
Contributor Author

nexus-aissam commented Jan 5, 2025

Response to Test Case Addition

@aravindnc I have added a test case that verifies the leanWithVirtuals functionality. The test confirms the following functionality:

it('should work with lean and leanWithVirtuals options', async function () {
    var options = {
        limit: 10,
        page: 1,
        lean: true,
        leanWithVirtuals: true,
        populate: {
            path: 'user'
        }
    };
    // Test verifies:
    // 1. Virtual fields in populated docs
    // 2. Lean object conversion
    // 3. Correct virtual field computation
    // 4. Pagination functionality
});

Test Coverage

  • ✅ Virtual fields inclusion in populated documents
  • ✅ Lean object conversion verification
  • ✅ Virtual field value computation
  • ✅ Pagination functionality with options enabled

@aravindnc aravindnc merged commit b78f359 into aravindnc:main Jan 6, 2025
3 checks passed
@aravindnc
Copy link
Owner

Awesome. Thanks for the support. I've updated the package. @nexus-aissam

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

Successfully merging this pull request may close these issues.

2 participants